none
Azure Blob Download RRS feed

  • Question

  • Hi,

    1. I am using Azure to store short video clips as Block blobs
    2. Lunching http://XXX.cloudapp.net/myfile.mp4 using IE opens a portable player and play the file
    3. I need these blobs to be downloadable ( saved to the local consumer HDD ) and not played using the registered player.
    4. I have set the Blob 'Content-Type' to 'application/zip' ( as the Blob metadata property ).
    5. Using a network sniffer I can see that the proper ( application/zip ) Content-Type is used, still, I get the registered player invoked by IE rather then being asked ( by the browser ) where to save the file.

    Is there any way to force IE to save the blob to the disk, w/o usage of the SaveAs context menu item, and, w/o redirecting it through my web-site ?

    Any help will B appreciated.


    Nadav Rubinstein, See my Blog @ http://www.sophin.com
    • Edited by Nadav Rub Thursday, December 29, 2011 9:04 AM
    Thursday, December 29, 2011 9:00 AM

Answers

  • Personally, I would try several different Content-Types to get through this if you wish to do this code free. Here's a good list for you to work through:

    http://mimeapplication.net/type-list-1

    We had this problem in the past for a project we did and I believe we solved it by setting the Content-Type to text or something along those lines. 


    -Ira Bell
    Thursday, January 5, 2012 8:50 PM
  • This will work, BUT, will req routing the content through my WebRole and will req to host it all on the web server memory before it can be sent back to the peer
    Nadav Rubinstein, See my Blog @ http://www.sophin.com


    Hi Nadav,

    Azure account and secret key are used to protect your important data in Azure Storage, if you want to share your resources to customers, i suggest you create a WCF service for achieving your goals, client-side application can get the resources if they through your validation.

    For share some code snippets:

        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            byte[] GetData(string containerName, string fileName);
        }
    
    
    
        public class Service1 : IService1
        {
    
    
            public byte[] GetData(string containerName, string fileName)
            {
                CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=<your account>;AccountKey=<you key word>");
                CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
                CloudBlob cloudBlob = cloudBlobContainer.GetBlobReference(fileName);
                byte[] byteData = cloudBlob.DownloadByteArray();
                return byteData;
            }
        }

    You can use WCF Service to connect the Cloud Blob Storage, the client only need to provide blob container name and file name to specify a blob file and here we return byte array for downloading.

    Hope it can help you.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
    Thursday, December 29, 2011 6:12 PM
    Moderator

All replies

  • Hello nadav,

     

                             Try the below snippet :

                        

                            HttpContext.Current.Response.Clear();
                            HttpContext.Current.Response.ContentType = "file";
                            HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}{1}", fileName, fileType));
                            HttpContext.Current.Response.Charset = string.Empty;
                            MemoryStream stream = new MemoryStream();
                            blob.DownloadToStream(stream);
                            HttpContext.Current.Response.BinaryWrite(stream.ToArray());
    


    Sudhesh. G
    http://gurucoders.blogspot.com
    Thursday, December 29, 2011 10:22 AM
  • This will work, BUT, will req routing the content through my WebRole and will req to host it all on the web server memory before it can be sent back to the peer
    Nadav Rubinstein, See my Blog @ http://www.sophin.com
    • Edited by Nadav Rub Thursday, December 29, 2011 11:50 AM
    Thursday, December 29, 2011 10:38 AM
  • This will work, BUT, will req routing the content through my WebRole and will req to host it all on the web server memory before it can be sent back to the peer
    Nadav Rubinstein, See my Blog @ http://www.sophin.com


    Hi Nadav,

    Azure account and secret key are used to protect your important data in Azure Storage, if you want to share your resources to customers, i suggest you create a WCF service for achieving your goals, client-side application can get the resources if they through your validation.

    For share some code snippets:

        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            byte[] GetData(string containerName, string fileName);
        }
    
    
    
        public class Service1 : IService1
        {
    
    
            public byte[] GetData(string containerName, string fileName)
            {
                CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=<your account>;AccountKey=<you key word>");
                CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
                CloudBlob cloudBlob = cloudBlobContainer.GetBlobReference(fileName);
                byte[] byteData = cloudBlob.DownloadByteArray();
                return byteData;
            }
        }

    You can use WCF Service to connect the Cloud Blob Storage, the client only need to provide blob container name and file name to specify a blob file and here we return byte array for downloading.

    Hope it can help you.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
    Thursday, December 29, 2011 6:12 PM
    Moderator
  • Personally, I would try several different Content-Types to get through this if you wish to do this code free. Here's a good list for you to work through:

    http://mimeapplication.net/type-list-1

    We had this problem in the past for a project we did and I believe we solved it by setting the Content-Type to text or something along those lines. 


    -Ira Bell
    Thursday, January 5, 2012 8:50 PM