node.jsamazon-web-servicesamazon-s3gzipcontent-encoding

AWS S3 serving gzipped files but not readable


I'm using AWS S3 to host a static webpage, almost all assets are gzipped before being uploaded.

During the upload the "content-encoding" header is correctly set to "gzip" (and this also reflects when actually loading the file from AWS).

The thing is, the files can't be read and are still in gzip format although the correct headers are set...

The files are uploaded using npm s3-deploy, here's a screenshot of what the request looks like:

file request

and the contents of the file in the browser:

file contents

If I upload the file manually and set the content-encoding header to "gzip" it works perfectly. Sadly I have a couple hundred files to upload for every deployment and can not do this manually all the time (I hope that's understandable ;) ).

Has anyone an idea of what's going on here? Anyone worked with s3-deploy and can help?


Solution

  • I use my own bash script for S3 deployments, you can try to do it:

    webpath='path'
    BUCKET='BUCKETNAME'
    
    for file in $webpath/js/*.gz; do
            aws s3 cp "$file" s3://"$BUCKET/js/" --content-encoding 'gzip' --region='eu-west-1'
    done