1

I have a WCF REST service with Azure Blob Storage. I don't want to use my service as a proxy with a stream, so I wanted to redirect client's request to the absolute blob url but it redirects to the file and tries to open it directly. All I want is starting download process when server redirects the request to the absolute blob url. The code which I have tried is below:

    var sas = blob.GetSharedAccessSignature(new SharedAccessPolicy
    {
        Permissions = SharedAccessPermissions.Read,
        SharedAccessStartTime = DateTime.UtcNow,
        SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromMinutes(1)
    });
    WebOperationContext.Current.OutgoingResponse.ContentType = blob.Properties.ContentType;
    WebOperationContext.Current.OutgoingResponse.ContentLength = blob.Properties.Length;
    WebOperationContext.Current.OutgoingResponse.Location = blob.Uri.AbsoluteUri+sas;
    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Redirect;

P.S. I tried to change status code to Redirect, Moved.. etc. but nothing changes.

Update If I change ContentType to application/octet-stream, it results like this in IE:

<base64Binary xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
...
</base64Binary>
iboware
  • 977
  • 1
  • 12
  • 25

1 Answers1

1

Possible duplicate of this question.

Since Stive Marx sais that there is no way to control the "content-disposition" header for Azure Lbob, there is no way for force browser (IE) to download the file. Having the content-type set to "application/octet-stream" might force some browsers to downlaod the file, instead of opening it, but apparently it does not work for IE.

Community
  • 1
  • 1
astaykov
  • 30,768
  • 3
  • 70
  • 86
  • yes, it works on Firefox and Chrome but it doesn't work enough correct. Browser does not know what is the real name of file and extension. Do you know, what is the best way to download big files from azure. Is a Stream correct way to do it? Because to create a stream, server have to download data before sending it to client. – iboware Jan 06 '12 at 21:25
  • Well, for non-images I usually zip the files. With the ZIP extension and the application/x-zip-compressed content type, the files are usually downloaded insted of displayed inline. – astaykov Jan 06 '12 at 21:33
  • thanks, I'll wait for another responses a bit, and I'll search about the best practise to do this in the most correct way then I'll mark your answer as accepted. – iboware Jan 06 '12 at 21:47