Menu
Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)

Using the AWS PHP SDK for Multipart Upload

You can upload large files to Amazon S3 in multiple parts. You must use a multipart upload for files larger than 5 GB. The AWS SDK for PHP exposes the MultipartUploader class that simplifies multipart uploads.

The upload method of the MultipartUploader class is best used for a simple multipart upload. If you need to pause and resume multipart uploads, vary part sizes during the upload, or do not know the size of the data in advance, use the low-level PHP API. For more information, see Using the AWS PHP SDK for Multipart Upload (Low-Level API).

For more information about multipart uploads, see Uploading Objects Using Multipart Upload API. For information on uploading files that are less than 5GB in size, see Upload an Object Using the AWS SDK for PHP.

Upload a File Using the High-Level Multipart Upload

This topic explains how to use the high-level Aws\S3\Model\MultipartUpload\UploadBuilder class from the AWS SDK for PHP for multipart file uploads. It assumes that you are already following the instructions for Using the AWS SDK for PHP and Running PHP Examples and have the AWS SDK for PHP properly installed.

The following PHP example uploads a file to an Amazon S3 bucket. The example demonstrates how to set parameters for the MultipartUploader object.

For information about running the PHP examples in this guide, see Running PHP Examples.

<?php require 'vendor/autoload.php'; use Aws\Common\Exception\MultipartUploadException; use Aws\S3\MultipartUploader; use Aws\S3\S3Client; $bucket = '*** Your Bucket Name ***'; $keyname = '*** Your Object Key ***'; $s3 = new S3Client([ 'version' => 'latest', 'region' => 'us-east-1' ]); // Prepare the upload parameters. $uploader = new MultipartUploader($s3, '/path/to/large/file.zip', [ 'bucket' => $bucket, 'key' => $keyname ]); // Perform the upload. try { $result = $uploader->upload(); echo "Upload complete: {$result['ObjectURL']}" . PHP_EOL; } catch (MultipartUploadException $e) { echo $e->getMessage() . PHP_EOL; }

Related Resources

On this page: