简体   繁体   English

php 页面中的 aws s3 listobjectsv2

[英]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.

相关问题 S3 存储桶的 ListObjectsV2 操作的访问被拒绝 - AccessDenied for ListObjectsV2 operation for S3 bucket aws-sdk S3:使用 listObjectsV2 列出所有键的最佳方式 - aws-sdk S3: best way to list all keys with listObjectsV2 aws S3 ListObjectsV2 api 中的 start-after 是什么意思? - What does start-after in aws S3 ListObjectsV2 api mean? 跳过 Amazon S3 ListObjectsV2 中的前“n”个键 - Skip first "n" keys in Amazon S3 ListObjectsV2 S3 ListObjectsV2 能否返回从最新到最旧排序的键? - Can S3 ListObjectsV2 return the keys sorted newest to oldest? 当 MLFlow 尝试访问存储在 S3 上的人工制品时,获取“(InvalidToken)调用 ListObjectsV2 操作时” - Getting "(InvalidToken) when calling the ListObjectsV2 operation" when MLFlow is trying to access the artefacts stored on S3 listObjectsV2 使用 nodejs 列出嵌套“文件夹”中的所有对象 - listObjectsV2 to list all the objects from nested "folders" using nodejs 使用 SDK 将对象上传到 AWS S3 3 for PHP - Uploading Objects to AWS S3 with SDK 3 for PHP 使用批处理作业时“调用 ListObjectsV2 操作时发生错误 (AccessDenied):访问被拒绝” - "An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied" when using batch jobs PHP - 使用 REST API 从 AWS S3 中删除 object - PHP - Delete object from AWS S3 with REST API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM