Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure File storage content-type is always application/octet-stream

I'm currently having issue with Azure File storage when I build up a URL with a shared access signature (SAS) Token. The file will download in the browser, but the content-type is always application/octet-stream rather than changing to match the mime type of the file. If I put the file in Azure BLOB storage and build up a URL with a SAS Token, it sends the correct content-type for my file (image/jpeg).

I've upgraded my storage account from V1 to V2 thinking that was the problem, but it didn't fix it.

Does anyone have a clue what I could try that might get Azure File storage to return the correct content-type using a URL with SAS Token to download the file?

like image 916
David Yates Avatar asked Apr 24 '18 22:04

David Yates


3 Answers

Check this out - Microsoft SAS Examples

If you don't want to update the content-type of your file in Azure or it's too much of a pain to update the content-type of all your existing files, you can pass the desired content-type w/ the SAS token as well. The rsct param is where you would specify the desired content-type.

e.g. - https://myaccount.file.core.windows.net/pictures/somefile.pdf?sv=2015-02-21&st=2015-07-01T08:49Z&se=2015-07-02T08:49Z&sr=c&sp=r&rscd=file;%20attachment&rsct=application%2Fpdf&sig=YWJjZGVmZw%3d%3d&sig=a39%2BYozJhGp6miujGymjRpN8tsrQfLo9Z3i8IRyIpnQ%3d

like image 147
TWong Avatar answered Oct 03 '22 06:10

TWong


So far these are the only fixes for the content-type that I've found:

  1. Use the Microsoft Azure Storage Explorer to modify the content-type string by hand. You have to right click the file and the left-click properties to get the dialog to appear.
  2. Programmatically modify the file using Microsoft's WindowsAzure.Storage Nuget package.
  3. Surface file download via my own web site and not allow direct access.

For me, none of these are acceptable choices. The first two can lead to mistakes down the road if a user uploads a file via the portal or Microsoft Azure Storage Explore and forgets to change the content type. I also don't want to write Azure Functions or web jobs to monitor and fix this problem.

Since blob storage does NOT have the same problems when uploading via Microsoft Azure Storage Explore or via the portal, the cost is much lower AND both work with SAS Tokens, we are moving towards blob storage instead. We do lose the ability to mount the drive to our local computers and use something like Beyond Compare to do file comparisons, but that is a disadvantage that we can live with.

If anyone has a better solution than the ones mentioned above that fixes this problem, I will gladly up-vote it. However, I think that Microsoft will have to make changes for this problem to be fixed.

like image 23
David Yates Avatar answered Oct 03 '22 05:10

David Yates


When I upload a jpeg file to file share through portal, content-type is changed to application/octet-stream indeed. But I can't reproduce your download problem.

I didn't specify content-type in my SAS request uri, but the file just download as a jpeg file. Have tested in SDK(Account SAS/Stored Access Policy/SAS on file itself) or REST API, both work even without content-type.

You can try to specify the content-type using the code below.

 SharedAccessFileHeaders header = new SharedAccessFileHeaders()
 {
     ContentDisposition = "attachment",
     ContentType = "image/jpeg"
 };
string sasToken = file.GetSharedAccessSignature(sharedPolicy,header);
like image 22
Jerry Liu Avatar answered Oct 03 '22 05:10

Jerry Liu