Since Digital Ocean Spaces API is compatible with AWS SDK, how to upload images to Digital Ocean Spaces programmatically using AWS SDK for 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代码在 digital ocean 中上传图片:
配置客户端:
使用 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' ]);
关于php - 如何使用适用于 Yii2 的 AWS SDK 将图像上传到数字 Ocean Spaces?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60937975/