php - 亚马逊s3批量上传

标签 php amazon-s3

我一直在尝试使用 s3 客户端 execute() 方法进行批量上传。它不断抛出异常:

Message: Argument 1 passed to Aws\AwsClient::execute() must implement interface Aws\CommandInterface, array given, called in....

即使遵循了文档中的示例代码。

检查这个例子,也许我做错了什么:

$bucket   = 'myBucket';
$commands = [];

$s3 = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-west-1',
]);

$commands[] = $s3->getCommand('PutObject', [
    'Bucket' => $bucket,
    'Key'    => 'key1.gif',
    'Body'   => 'PATH_TO_FILE_1',
]);

$commands[] = $s3->getCommand('PutObject', [
    'Bucket' => $bucket,
    'Key'    => 'key2.gif',
    'Body'   => 'PATH_TO_FILE_2',
]);

$s3->execute($commands);

提前致谢!

最佳答案

我自己解决了这个问题。

不是调用 $s3->execute(),而是将客户端和 $commands 数组传递给 CommandPool像这样:

use Aws\CommandPool;

// your code here

$results = CommandPool::batch($s3, $commands);

您将收到一组结果,按照与命令相同的顺序排序。其中一个区别是,如果命令失败,这还将包括 Exception 对象。

关于php - 亚马逊s3批量上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39640723/

相关文章:

ruby-on-rails - NameError:升级到 rails3 时未初始化的常量 Test::Unit::AssertionFailedError

php - 对于每个数据 jquery ajax

php - 控制帖子图像大小移动

php - Shopify Webhooks 到 Laravel 路线

apache-spark - presto 是否需要 Hive Metastore 才能从 S3 读取 Parquet 文件?

javascript - 保护亚马逊存储桶中的 json 数据

ios - iOS AWS v2 S3 Transfer Manager必须使用指定的端点

php - 打印 mysqli 查询结果

php - 如何在 html 中为数据库表的列使用复选框?

c# - Xamarin - 找不到元数据文件 .../AWSSDK.SecurityToken.CodeAnalysis.dll