[英]aws s3 listobjectsv2 in php page
I'm using the aws sdk to connect to an s3 bucket.我正在使用 aws sdk 连接到 s3 存储桶。 I have built an IAM Policy to allow read using "s3:GetObject", "s3:GetObjectAcl" and "s3:ListBucket" and I can use the AWS cli to view objects and list files (including with listobjectsv2).我已经构建了一个 IAM 策略以允许使用“s3:GetObject”、“s3:GetObjectAcl”和“s3:ListBucket”进行读取,并且我可以使用 AWS cli 查看对象和列表文件(包括 listobjectsv2)。 When I use:当我使用时:
$file = $s3client->getObject([
'Bucket' => $bucket,
'Key' => $key,
]);
$body = $file->get('Body');
$body->rewind();
echo "Downloaded the file and it begins with: {$body->read(26)}.\n";
I can view file contents but when I try:我可以查看文件内容,但是当我尝试时:
$contents = $s3client->listObjectsV2([
'Bucket' => $bucket
]);
echo "The contents of your bucket are: \n";
foreach ($contents['Contents'] as $content) {
echo $content['Key'] . "\n";
I receive a super helpful error:我收到一个超级有用的错误:
Fatal error: Uncaught Error: Class 'SimpleXMLElement' not found in /var/www/html/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php:39 Stack trace: ....
It goes on but I figure it's all trash so not continuing.它继续,但我认为这都是垃圾,所以不会继续。 I grabbed the code straight from: https://docs.aws.amazon.com/code-samples/latest/catalog/php-s3-s3_basics-GettingStartedWithS3.php.html Any suggestions on what is wrong?我直接从以下位置获取代码: https://docs.aws.amazon.com/code-samples/latest/catalog/php-s3-s3_basics-GettingStartedWithS3.php.html有什么问题的建议吗?
sudo apt-get install php-xml sudo apt-get install php-xml
doh哦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.