如何从Amazon AWS S3版本2中获取文件大小?

7

由于无法将PHP更新到5.5版本,我被迫使用AWS S3的第二个版本,而不是第三个版本。

我编写了这个PHP脚本来从AWS下载文件,它运行良好:

//http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.S3Client.html#_createPresignedUrl
// Get a command object from the client and pass in any options
// available in the GetObject command (e.g. ResponseContentDisposition)
$command = $s3Client->getCommand('GetObject', array(
    'Bucket' => $bucket,
    'Key' => $objectKey,
    'ResponseContentDisposition' => 'attachment; filename="' . $originFilename . '"'
));

// Create a signed URL from the command object that will last for
// 10 minutes from the current time
$signedUrl = $command->createPresignedUrl('+1000 minutes');

$file = file_get_contents($signedUrl);

问题是我想确保file_get_contents()下载整个文件,并检测和修复任何错误(例如在下载期间服务器离线等),因此我考虑以下流程:
  1. 向AWS请求文件大小
  2. 下载文件
  3. 检查文件大小。如果不相等,则重新下载文件
那么,如何从AWS获取文件大小?我找到了这个链接,但它不适用于我的版本。
1个回答

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接