elecena/amazon-s3-php-class

Support multipart uploads to S3 for larger files

macbre opened this issue · 1 comments

AWS S3 docs say that the maximum object size that can be stored on S3 in 5 TiB. However, one then needs to use the multipart uploads process:

Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without affecting other parts. After all parts of your object are uploaded, Amazon S3 assembles these parts and creates the object. In general, when your object size reaches 100 MB, you should consider using multipart uploads instead of uploading the object in a single operation.

-- Uploading and copying objects using multipart upload

You must initiate a multipart upload (see CreateMultipartUpload) before you can upload any part. In response to your initiate request, Amazon S3 returns an upload ID, a unique identifier, that you must include in your upload part request.

Part numbers can be any number from 1 to 10,000, inclusive. A part number uniquely identifies a part and also defines its position within the object being created. If you upload a new part using the same part number that was used with a previous part, the previously uploaded part is overwritten.

-- UploadPart

This action concatenates the parts that you provide in the list. For each part in the list, you must provide the part number and the ETag value, returned after that part was uploaded.

Processing of a Complete Multipart Upload request could take several minutes to complete. After Amazon S3 begins processing the request, it sends an HTTP response header that specifies a 200 OK response. While processing is in progress, Amazon S3 periodically sends white space characters to keep the connection from timing out. Because a request could fail after the initial 200 OK response has been sent, it is important that you check the response body to determine whether the request succeeded.

-- CompleteMultipartUpload


Docs on how to implement the multipart upload using AWS S3 REST API.

I'm starting writing some code for this enhancement, and following the documentation, the first step is to initiates a multipart upload that returns an upload ID

Request Syntax
POST /{Key+}?uploads HTTP/1.1
Host: Bucket.s3.amazonaws.com

Example
https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html#API_CreateMultipartUpload_Examples

but when i try to send the request

$rest = new S3Request("POST", "MYBUCKET", "file1?uploads", self::$endpoint);
$rest->getResponse();

i have this response:

"MethodNotAllowed"
"The specified method is not allowed against this resource."