Azure-storage-azcopy: ContentType for JSON objects not correctly identified

Created on 28 Sep 2018  路  6Comments  路  Source: Azure/azure-storage-azcopy

Which version of the AzCopy was used?

10.0.1-Preview

Which platform are you using? (ex: Windows, Mac, Linux)

Windows & Linux

What command did you run?

Note: Please remove the SAS to avoid exposing your credentials. If you cannot remember the exact command, please retrieve it from the beginning of the log file.

azcopy /SetContentType

What problem was encountered?

ContentType detection makes use of the built-in http.DetectContentType in Go, however this does not correctly identify the content type of JSON files (as well as JavaScript files and SVG images). This is particularly problematic when uploading material to be used in a static website. See the following for detail of the problem caused and some work-arounds:

https://liftcodeplay.com/2017/11/28/how-to-fix-azure-storage-blob-content-types/

How can we reproduce the problem in the simplest way?

Use azcopy on a test.json file and inspect the content type, set as application/octet-stream which then prevents the JSON from loading correctly in a client browser. Copy the same file using the Azure Storage Explorer and the correct content type is detected.

Have you found a mitigation/solution?

Two approaches to mitigation;

  1. Crawl all the files in the container after copying and set correct content types based on file extension or;
  2. Copy all files and then do a second invocation of AzCopy to copy the *.json files with an explicit Content Type set, i.e. AzCopy\AzCopy.exe" /Source:"" /Dest:"https://my.blob.core.windows.net/$web" /Pattern:"*.json" /S /Y /SetContentType:"application/json" /Z /V

A better solution for customers would be to have some additional extra file extension based ContentType heuristics in AzCopy for common miss-detected types. The JSON mime-type issue is particularly problematic and hard for end-users to debug as a content type problem.

enhancement

Most helpful comment

Hi @martinwoodward, thanks for reaching out!

The sample command in your description is actually for AzCopy V8; we've dramatically changed the command-line interface in V10.

Nevertheless, I tried uploading a json and js file using AzCopyV10, and got "text/plain" for both content-types. I've added an item to our backlog to improve the content type detection. Thank you very much for the suggestion!

All 6 comments

Hi @martinwoodward, thanks for reaching out!

The sample command in your description is actually for AzCopy V8; we've dramatically changed the command-line interface in V10.

Nevertheless, I tried uploading a json and js file using AzCopyV10, and got "text/plain" for both content-types. I've added an item to our backlog to improve the content type detection. Thank you very much for the suggestion!

@zezha-msft This enhancement would be greatly appreciated!

Hi @eddiedozier, we are actively working on this enhancement. Thanks!

This is fixed.

which version of azcopy fixed the problem?

AzCopy 10.2.1 does not properly set/detect the content-type for *.json files for me.

as it seems, 10.2.x has a small list of content-types baked in, that works for *.js, *.css, *.html and maybe even some more. If you need *.json support you may add it via /etc/mime.types with a line like this:

application/json json

Was this page helpful?
0 / 5 - 0 ratings