Sharing programming tips and tricks

Adding custom metadata on AWS S3 pre-signed url generation

While uploading file to S3, we sometime need to store some metadata associated with a file, such as Content-Type, custom metadata etc. Content-Type metadata can be easily added as header while uploading to S3, but custom metadata needs a bit more work.

Here is the file upload flow for a mobile app:

Figure: File Upload flow from mobile app to S3

After uploading file, we have a lambda which scales the image to a specific dimension determined by a custom metadata: ‘imageType’ (business type, not content-type) associated with file.

I have not found any useful documentation on how to put the metadata programmatically while signing the url request. After trying out, I found the following solution.

While asking for pre-signed url from app, app sends the ‘imageType’ (profile/other etc) input. Backend takes that field and sends as user-metadata to S3 for signing in the following way using field: “x-amz-meta-image-type”