Issue: 0 bytes/ empty file after uploading to S3 using the pre-signed URL

I am struggling in getting a file uploaded to S3 using a pre-signed URL by a Lambda function. The file is uploaded successfully but with 0 bytes.

In terms of uploading objects to S3, Amazon S3 offers the 2 options:

  1. Upload objects in a single operation—With a single PUT operation, you can upload objects up to 5 GB in size.
  2. Upload objects in parts—Using the multipart upload API, you can upload large objects, up to 5 TB. The multipart upload API is designed to improve the upload experience for larger objects. You can upload objects in parts. These object parts can be uploaded independently, in any order, and in parallel. You can use a multipart upload for objects from 5 MB to 5 TB in size.

when I use “putObject” as operation input for calling getSignedUrl(), the required parameters are Bucket and Key, others are optional. The expected operation parameters looks like:

var params = {
    Bucket: 'STRING_VALUE', /* required */ 
    Key: 'STRING_VALUE', /* required */
    …
}

However,it is recommended to explicitly add more parameters (eg. Content-Type) with getSignedUrl method. Sometimes the browser adds the content-type to the request headers automatically. In addition, please make sure that the ContentType that is used to generate the signed URL should match the Content-Type header of the request to the signed URL.

Another key point is the FormData. When you are trying to upload FormData, it will cause corrupted data to be uploaded. You should not use FormData and instead provide only the file object as a payload.

Also in some cases, the encoding in reading file could cause missing issue. For example, when you use a UTF-8 encoding rading a pdf file, the uploaded file could missing embedded images. So it depends on your use case or just use default one (without explicit encoding).

1 Comment

  • Hairstyles September 22, 2020

    I’m just commenting to make you understand of the remarkable experience my friend’s daughter obtained viewing your site. She noticed so many pieces, which included what it’s like to have an excellent coaching character to have other folks quite simply master a variety of impossible things. You really exceeded her expected results. Thanks for displaying such necessary, trusted, informative and even unique tips on the topic to Kate.

Leave a Reply