0

I have the following code on my page:

<a class="btn-default btn" href="<AzureBlobContainerUrl>/<guid>.psd" download="@Model.FileName" target="_blank">Download 
    <span class="glyphicon glyphicon-export"></span>
</a>

@Model.FileName represents e.g. 'MyPhotoshopFile.psd'

First Problem: The downloaded file has the original GUID as filename not e.g. 'MyPhotoshopFile.psd'.

Second Problem: If the file is a e.g. PDF then Google opens the file directly in the current browser tab instead of downloading it.

Any solutions for that?

WhiteIntel
  • 697
  • 1
  • 9
  • 24

2 Answers2

1

For the first problem, try setting the Content-Disposition property on the blob. If you're using the C# SDK, then grab the blob and you can set the C-D using something like this:

blob.FetchAttributes();
blob.Properties.ContentDisposition = string.Format("attachment;filename=\"{0}\"", yourFileName);
blob.SetProperties();

Based on this older question (Chrome Download Attribute not working), the "download" attribute in Chrome behaves differently based on the C-D, so setting this explicitly will likely solve your second problem.

Bryan Lewis
  • 5,629
  • 4
  • 39
  • 45
  • Where can I set blob.FetchAttributes(); etc. and where can I set the Content-Disposition header? I´m on a cshtml partial page. – WhiteIntel Mar 09 '20 at 17:10
  • 1
    @WhiteIntel, it may be best to try to set the C-D at the time the blob is added to azure storage, if that is possible. Then you don't have to worry about it later. If that's not possible, then you could do it before the page is rendered (are you using MVC or Razor pages?) – Bryan Lewis Mar 09 '20 at 17:15
0

Well, thank you very much for your tips! First, the code and your advice weren't working (the C-D attribute was ignored by azure blos storage services), but after some hours of research I identified the issue:

  • AccountKind StorageV2 (general purpose v2) is NOT working with the C-D attribute
  • AccountKind BlobStorage is working without any problems

I recreated the blob storage and used the legacy BlobStorage account type. With this the ContentDisposition Attribute is working.

WhiteIntel
  • 697
  • 1
  • 9
  • 24
  • 1
    This is not an answer to the question. It's more like a comment to the answer provided by Bryan or an update to the question. – Gaurav Mantri Mar 10 '20 at 00:23
  • Well this is an answer to my question, because this exactly resolved my problems. – WhiteIntel Mar 10 '20 at 12:05
  • I'm actually surprised that the solution didn't work for V2 account but is working for Blob Storage accounts. Content-Disposition property should work for both types of accounts. I thought you were sharing your observations, hence my comment. – Gaurav Mantri Mar 10 '20 at 12:10
  • No problem! :) I´m wondering too, we tried it with several test accounts, same result: not working, I will submit the issue to microsoft these days – WhiteIntel Mar 10 '20 at 14:47