1

I have an SVG file on amazon s3. When I run the following command to download the file:

aws s3 cp s3://mybucket/test.svg .

It downloads it as a binary file. However if I directly go to the console and download from the GUI it's correctly downloaded as a text/xml file.

Any ideas how to preserve the file content type with aws s3 cp ?

Arafat Nalkhande
  • 11,078
  • 9
  • 39
  • 63
  • What is the `Content-Encoding` of the file, as shown in the S3 console? – Michael - sqlbot Nov 28 '16 at 00:02
  • content-engoding says `gzip`. Is there a way to mass-download the files in their original format? – Vahed Qazvinian Nov 28 '16 at 00:36
  • 1
    You are getting the "original" format, from S3's perspective. S3 doesn't modify content -- ever. This can only be explained by the files being gzipped before they were originally uploaded to S3, with the `Content-Encoding` header correctly set to indicate this. Browsers generally decompress on the fly, when the object is compressed and `Content-Encoding: gzip` is present, but the CLI doesn't. – Michael - sqlbot Nov 28 '16 at 01:01
  • thank you! thank makes sense. – Vahed Qazvinian Nov 28 '16 at 01:25
  • 1
    What you are seeing is correct. For more details see http://stackoverflow.com/questions/40972601/downloading-images-from-aws-gives-me-corrupt-files – Arafat Nalkhande Dec 12 '16 at 07:37
  • A bit cumbersome, but after renaming the downloaded file to `.gz` I decompressed it via `gunzip path/to/file.html.gz` (on mac), as per this https://stackoverflow.com/questions/50993318/uncompress-a-txt-gz-file-in-mac/50996888 and then I could view the file via vim. – Neara Dec 15 '21 at 09:40

1 Answers1

0

You can use the content-type option of the cp command (see full doc for reference)

aws s3 cp s3://mybucket/test.svg . --content-type 'image/svg+xml'
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • that didn't fix it. It almost looks like `s3 cp` encrypts or compresses the file. The downloaded svg is significantly smaller in size. – Vahed Qazvinian Nov 27 '16 at 23:40
  • Update: Looks like our s3 bucket was serving gzip encoded files. When clicking on the svg in the browser, it renders fine, but when downloading it gets the gzipped file. Not an `s3 cp` problem I guess. – Vahed Qazvinian Nov 28 '16 at 00:36