由于Digital Ocean Spaces API与AWS开发工具包兼容,因此如何使用AWS开发工具包以编程方式将图像上传到Digital Ocean Spaces为Yii2?
这里是我的详细信息
Good, we have the following data:
1. endpoint: fra1.digitaloceanspaces.com
2. bucket name: dev-abc
3. api key: xxxxxxxxxxxxx and api secret: xxxxxxx
4. The url that you need to use to deliver assets is https://dev-abc
我尝试过使用此代码无法正常工作
$uploader = new FileUpload(FileUpload::S_S3, [
'version' => 'latest',
'region' => 'fra1',
'endpoint' => 'https://fra1.digitaloceanspaces.com',
'credentials' => [
'key' => 'xxxxxxxxxxxxx ',
'secret' => 'xxxxxxx'
],
'bucket' => 'dev-abc'
]);
您可以通过php代码在数字海洋中上传图像:
配置客户端:
使用Aws \ S3 \ S3Client;
$client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'endpoint' => 'https://nyc3.digitaloceanspaces.com',
'credentials' => [
'key' => getenv('SPACES_KEY'),
'secret' => getenv('SPACES_SECRET'),
],
]);
创建新空间
$client->createBucket([
'Bucket' => 'example-space-name',
]);
上传图片
$client->putObject([
'Bucket' => 'example-space-name',
'Key' => 'file.ext',
'Body' => 'The contents of the file.',
'ACL' => 'private'
]);