AZCopy: Set the file Content-Type

We are trying to use AZCopy in our deployment script to upload some assets directly into our storage which is exposed via a CDN on Azure.

When we upload the files, the Content-Type is application/octet-stream but we would need to be able to specify by example text/javascript

Is there a way to achieve this? We don't bother having to call AZCopy several times for each file types.


The latest version of AzCopy (v3.1.0 and v4.1.0-preview) has included the support for setting content type, please download and find more details at http://aka.ms/azcopy.

To be more specific, you can set the content type via the option /SetContentType:[content-type].

AzCopy /Source:D:\test\ /Dest:https://myaccount.blob.core.windows.net/myContainer/ /DestKey:key /Pattern:ab /SetContentType

AzCopy /Source:D:\test\ /Dest:https://myaccount.blob.core.windows.net/myContainer/ /DestKey:key /Pattern:ab /SetContentType:video/mp4

If "Content-Type" is not specified at the /SetContentType option, AzCopy will set each blob’s content type according to its file extension. To set the same content type for all the blobs, you must explicitly specify a value for “Content-Type", for example, /SetContentType:video/mp4. Note that this option is only applicable when uploading blobs to the storage end points.


I found a way of doing this using Azure Pipelines:


- task: AzureFileCopy@4
  displayName: "Azure Storage - copy new files"
  inputs:
    SourcePath: '$(System.DefaultWorkingDirectory)/dist/*'
    azureSubscription: 'johnykes-PAYG(xxxxx-b455-4c4d-a8f8-c2a5fd479f10)'
    Destination: 'AzureBlob'
    storage: 'johnykeschatfrontend'
    ContainerName: '$web'

- task: AzureFileCopy@4
  displayName: "Azure Storage - overwrite .js files with correct Content Type"
  inputs:
    SourcePath: '$(System.DefaultWorkingDirectory)/dist/*.js'
    azureSubscription: 'johnykes-PAYG(xxxxx-b455-4c4d-a8f8-c2a5fd479f10)'
    Destination: 'AzureBlob'
    storage: 'johnykeschatfrontend'
    ContainerName: '$web'
    AdditionalArgumentsForBlobCopy: '--content-type "application/javascript"'

Please let me know if you find a way of doing this using the Azure CLI or in my way but recursively (for all .js files).


To add to the other answers here for anyone still finding this question, there is (now) an AzCopyConfig.json file where you can specify the MIME types for each file extension.

AzCopy determines content type of a blob based on a JSON file that stores content type to file extension mapping. This JSON file is named AzCopyConfig.json, and is located in the AzCopy directory. If you have a file type that is not in the list you can append the mapping to the JSON file:

{ "MIMETypeMapping": { ".myext": "text/mycustomtype", . . } }

Source: https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy#automatically-determine-content-type-of-a-blob