How to get file size with Amazon AWS S3 Version 2?

I am forced to use version 2 of AWS S3 because I cannot upgrade PHP to 5.5 on this server to use version 3.

I made this PHP script to download files from AWS, which works well:

//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);

The problem is that I want to be sure that it file_get_contents()downloads the entire file and detects and corrects any error (for example, the server shuts down at boot time, etc.), so I thought about the following thread:

  • I ask AWS file size
  • Upload file
  • I check the size. If it is not i, reload the file

So how to get file size with AWS? I found this one , but it does not work for my version.

+4
1

API HEAD Object REST , S3.

HEAD Object , S3, , Content-Length.

http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.S3Client.html#_headObject

+3

Source: https://habr.com/ru/post/1624312/


All Articles