Monday, October 30, 2023

AWS CLI sets wrong file type, file gets downloaded with the wrong extension

I recently experienced the following issue using the AWS CLI:

  1. I uploaded a .csv.gz file to S3.
  2. I generated a presigned link.
  3. The presigned link served the file with the wrong extension(.csv.csv instead of .csv.gz).
I think this is a bug in S3, where they misidentify the file type when a file has multiple extensions.
Thankfully, this can be easily solved, both for existing files, and for future uploads:
  • For existing files: I clicked on the object in the web interface, and scrolled down to Metadata.
    • Sure enough, the "Content-Type" key had the wrong value (it was "text/csv").
    • I clicked the "Edit" button, and manually changed it to the correct type, namely "application/x-gzip". They have The existing presigned link also reflected the change.
  • For future uploads: setting the content type explicitly ensures I will always get the desired content type, e.g.: --content-type application/x-gzip

No comments: