1

I am trying to upload a video file to S3 bucket using the PHP-SDK and a multipart upload. I managed to make it work via ajax already, but I want to know how to calculate and return the progress? I did a lot of research already but have not found any solutions yet.

Any help highly appreciated.

trainoasis
  • 6,419
  • 12
  • 51
  • 82
Gayadhar
  • 11
  • 2

1 Answers1

0

Here's an example using putObject, which can be converted into MultipartUpload:

$client = new S3Client(/* config */);

$result = $client->putObject([
    'Bucket'     => 'bucket-name',
    'Key'        => 'bucket-name/file.ext',
    'SourceFile' => 'local-file.ext',
    'ContentType' => 'application/pdf',
    '@http' => [
        'progress' => function ($downloadTotalSize, $downloadSizeSoFar, $uploadTotalSize, $uploadSizeSoFar) {
            printf(
                "%s of %s downloaded, %s of %s uploaded.\n",
                $downloadSizeSoFar,
                $downloadTotalSize,
                $uploadSizeSoFar,
                $uploadTotalSize
            );
        }
    ]
]);

This is explained in the AWS docs - S3 Config section. It works by exposing GuzzleHttp's progress property-callable, as explained in this SO answer.

Community
  • 1
  • 1
The Onin
  • 5,068
  • 2
  • 38
  • 55