摘要:接入rackspace传文件
[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
在Cloud Files/Containers可以看到
Client error response [status code] 401 [reason phrase] Unauthorized [url] https://identity.api.rackspacecloud.com/v2.0/tokens
这是因为在username 和apikey中用了{} 不应该按照文档来,应该去掉这个花括号
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');
}
}