Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between upload() and putObject() for uploading a file to S3?

In the aws-sdk's S3 class, what is the difference between upload() and putObject()? They seem to do the same thing. Why might I prefer one over the other?

like image 256
callum Avatar asked Jul 18 '16 17:07

callum


People also ask

What does S3 Putobject do?

Adds an object to a bucket. You must have WRITE permissions on a bucket to add an object to it. Amazon S3 never adds partial objects; if you receive a success response, Amazon S3 added the entire object to the bucket.

What is the best way for the application to upload the large files in S3?

When you upload large files to Amazon S3, it's a best practice to leverage multipart uploads. If you're using the AWS Command Line Interface (AWS CLI), then all high-level aws s3 commands automatically perform a multipart upload when the object is large. These high-level commands include aws s3 cp and aws s3 sync.

What happens if you upload the same file to S3?

If you pass the same key to upload a file, it is replaced, unless versioning is on. S3 supports versioning. This means that when you upload to the same key twice, two versions of the file are stored. Note that if you upload the exact same file twice, you get to pay for two identical copies of the same file on S3.


1 Answers

The advantage to using AWS SDK upload() over putObject() is as below:

  • If the reported MD5 upon upload completion does not match, it retries.
  • If the file size is large enough, it uses multipart upload to upload parts in parallel.
  • Retry based on the client's retry settings.
  • You can use for Progress reporting.
  • Sets the ContentType based on file extension if you do not provide it.
like image 64
error2007s Avatar answered Sep 28 '22 10:09

error2007s