jtbairdsr / spaces-api
为SociallyDev的出色Spaces-Api项目提供的composer包
dev-master
2018-01-29 20:07 UTC
Requires
- php: >=5.3.0
- aws/aws-sdk-php: ^3.52
- guzzlehttp/guzzle: ^6.3
- mtdowling/jmespath.php: ^2.4
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6
This package is not auto-updated.
Last update: 2024-09-29 05:14:50 UTC
README
一个为DigitalOcean的Spaces对象存储设计的API包装器,便于使用。
安装
> composer require jtbairdsr/spaces-api @dev
连接
require_once 'vendor/autoload.php'; $key = "EXAMPLE_KEY"; $secret = "EXAMPLE_SECRET"; $space_name = "my-space"; $region = "nyc3"; $space = new SpacesConnect($key, $secret, $space_name, $region);
所有可用选项
SpacesConnect(必需的密钥, 必需的秘密, 可选的SPACE名称, 可选的区域, 可选的主机);
上传/下载文件
$path_to_file = "image.png"; $space->uploadFile($path_to_file, "public"); $download_file = "image.png"; $save_as = "folder/downloaded-image.png"; $space->downloadFile($download_file, $save_as);
所有可用选项
uploadFile(必需的文件路径, 可选的隐私设置 (公开|私有), 可选的保存文件名称);
downloadFile(必需的下载文件, 必需的保存位置);
更改隐私设置
$file = "image.png"; $space->makePublic($file); $space->makePrivate($file);
所有可用选项
makePublic(必需的文件路径);
makePrivate(必需的文件路径);
创建临时链接
$file = "image.png"; $valid_for = "1 day"; $link = $space->CreateTemporaryURL($file, $valid_for);
所有可用选项
CreateTemporaryURL(必需的文件名, 可选的链接有效时间);
其他文件API
//List all files and folders $files = $space->listObjects(); //Check if a file/folder by that name already exists. True/False. $space->doesObjectExist($file_name); //Pull information about a single object. $file_info = $space->getObject($file_name); //Delete a file/folder. $space->deleteObject($file_name); //Upload a complete directory instead of a single file. $space->uploadDirectory($path_to_directory, $key_prefix); //Pull Access Control List information. $acl = $space-listObjectACL($file_name); //Update Access Control List information. $space->PutObjectACL($file_name, $acl_info_array);
创建Spaces
$new_space = "my-new-space"; $space->createSpace($new_space);
所有可用选项
createSpace(必需的Spaces名称, 可选的Spaces区域);
切换Spaces
$new_space = "my-new-space"; $space->setSpace($new_space);
所有可用选项
setSpace(必需的Spaces名称, 可选的Spaces区域, 可选的主机);
其他Spaces API
//List all Spaces available in account. $spaces = $space->listSpaces(); //Delete a Space. $space->destroyThisSpace(); //Download whole Space to a folder. $space->downloadSpaceToDirectory($directory_to_download_to); //Get the name of the current Space. $space_name = $space->getSpaceName(); //Pull the CORS policy of the Space. $cors = $space->listCORS(); //Update the CORS policy of the Space. $space->putCORS($new_policy); //Pull the Access Control List information of the Space. $acl = $space->listSpaceACL(); //Update the Access Control List information of the Space. $space->PutSpaceACL($new_acl);
处理错误
try { $space->createSpace("dev"); } catch (\Exception $e) { $error = $space->GetError($e); //Error management code. echo "<pre>"; print_r($error); /* EG: Array ( [message] => Bucket already exists [code] => BucketAlreadyExists [type] => client [http_code] => 409 ) */ }