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

Solution 1:

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.

Solution 2:

upload() allows you to control how your object is uploaded. For example you can define concurrency and part size.

From their docs: Uploads an arbitrarily sized buffer, blob, or stream, using intelligent concurrent handling of parts if the payload is large enough.

One specific benefit I've discovered is that upload() will accept a stream without a content length defined whereas putObject() does not.

This was useful as I had an API endpoint that allowed users to upload a file. The framework delivered the file to my controller in the form of a readable stream without a content length. Instead of having to measure the file size, all I had to do was pass it straight through to the upload() call.