接Rackspace

摘要:接入rackspace传文件

在接入的时候直接报错了CURL的CA验证错误

[curl] 60: SSL certificate problem: unable to get local issuer certificate
以为是之前那样就在本地配置了个pem直接在php.ini中配置了一个但是不起作用
后台联系客服才知道是SDK的问题
https://community.rackspace.com/products/f/dedicated-hybrid-hosting-forum/8674/rackspace-public-cloud-php-opencloud-sdk-errors-due-to-outdated-certificate-authority-list
在这里下载最新的pem按照地址对vendor中的pem进行替换
(一般会在这个位置/vendor/guzzle/guzzle/src/Guzzle/Http/Resources/cacert.pem.)
归档地址:http://files.guosx.com/cacert.pem

知道用的那个region

在Cloud Files/Containers可以看到

报错客户端错误

Client error response [status code] 401 [reason phrase] Unauthorized [url] https://identity.api.rackspacecloud.com/v2.0/tokens
这是因为在username 和apikey中用了{} 不应该按照文档来,应该去掉这个花括号

rackspace在子目录下放文件

rackspace不能直接创建子目录,但是却可以将文件放到子目录中
        $remoteFileName = 'finance/test4.png';
        $handle = fopen($localFileName, 'r');
        $object = $container->uploadObject($remoteFileName, $handle);
同时会看到在这个finance下面有个finance文件夹
这是一个坑点,其实他是正常的,你点开fiannce会发现那个头跟文件夹外面的头一样的,估计是rackspace做的一个处理,为了方便查看,下面 是两个头对比
Cloud FilesContainersOceaniafinance
Cloud FilesContainersOceaniafinance

上传文件代码示例

    /**
     * TODO Upload to Rackspace
     * Files larger than 5 GB must first be segmented into smaller files.
     * We recommend that you do not create file segments smaller than 100-200 MB.
     * Files larger than 10GB cannot be served from the CDN.
     * No type requirement
     *
     * @return array
     */
    public static function rs($data=array())
    {
        if(!empty($data) &&  !empty($data['myFile']['name'][0])){
            try{
                $up_files = $data['myFile'];
                // Instantiate a Rackspace client.
                $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
                    'username' => 'usernmae',
                    'apiKey'   => 'apiKey'
                ));
                // Obtain an Object Store service object from the client.
                $objectStoreService = $client->objectStoreService(null, 'HKG');
                //Get Container
                $container = $objectStoreService->getContainer('Oceania');
                //Enable container CDN
                $container ->enableCdn();
                //Upload an object to the container
                foreach ($up_files['tmp_name'] as $k=>$v){
                    if(empty($v) || $v==''){
                        continue;
                    }
                    $localFileName = $v;
                    $up_file_name = time().'-'.$up_files['name'][$k];
                    $remoteFileName = 'finance/' . $up_file_name;
                    $db_file_name[] = $up_file_name;
                    $handle = fopen($localFileName, 'r');
                    $container->uploadObject($remoteFileName, $handle);
                }
                return format_return_data(true,$db_file_name);
            }catch (\Exception  $e){
                return format_return_data(false,$e->getMessage());
            }
        }else{
            return format_return_data(false,'No files uploaded');
        }

    }
评论
  • 2018-12-13 15:58:49 by Eric Guo
    文件名不支持中文
  • 2018-12-13 11:54:43 by Eric Guo
    开发文档https://developer.rackspace.com/docs/cloud-files/quickstart/?lang=php
  • 2018-12-13 11:54:09 by Eric Guo
    上传大小限制文档,没有类型限制 https://support.rackspace.com/how-to/cloud-files-uploading-large-files/