none
file download from blob

    Question

  • Hi,

    Below code is for donwnloading file from azure blob. I have problem with .docx,.xlsx files and that too after deployment only, mean in local machine it is working fine.

    The problem is after downloading .xlsx or .docx, when i open that file showing file corrupted popup.

    Please help me some one.

    public void DownloadBlob(string blobName) { 
    string accountName = "MyAccName";
     string accountPrimaryKey = "MyKey"; 
    string blobContainer = "ContainerName"; 
    CloudStorageAccount account = new CloudStorageAccount(new StorageCredentialsAccountAndKey(accountName, accountPrimaryKey), false);
     CloudBlobClient blobClient = account.CreateCloudBlobClient();
     CloudBlobContainer container = blobClient.GetContainerReference(blobContainer); CloudBlob blob = container.GetBlobReference(blobName); 
    
    MemoryStream memStream = new MemoryStream(); 
    
    blob.DownloadToStream(memStream);
    
            Response.ContentType = blob.Properties.ContentType;
            Response.AddHeader("Content-Disposition", "Attachment; filename=" + blobName.ToString());
            Response.AddHeader("Content-Length", (blob.Properties.Length - 1).ToString());
            Response.BinaryWrite(memStream.ToArray());
            Response.End();
        }
    

    • Moved by Mike Feng Thursday, May 10, 2012 5:59 AM Azure Storage (From:.NET Base Class Library)
    Tuesday, May 8, 2012 11:18 AM

Answers

  • This has been asked over on StackOverflow too, but it looks like the user has abandoned it: http://stackoverflow.com/questions/10497449/file-download-from-azure-blob

    No sense answering here.

    Thursday, May 10, 2012 9:39 AM
  • Hello,

    According to your description, you mentioned that "I have problem with .docx,.xlsx files and that too after deployment only, mean in local machine it is working fine." Is that mean the .docx and .xlsx files can be downloaded success in storage emulator (local SQL Server databse), but now works in Cloud Storage? or works fine at local machine with cloud Storage but not in cloud environment with cloud storage? And i suggest you provide more details about your exception message, such as Stack message or tracing logs.

    And please following Steve's suggestion check "blob.Properties.Length - 1" in HttpRequest Header.

    Here is the difference between Azure Cloud Storage and Azure Storage Emulator:

    http://msdn.microsoft.com/en-us/library/windowsazure/gg433135.aspx

    And i saw your blob container name is "ContainerName". is this a true container name or repalcer, if it's a ture container name will cause errors, Blob container name must be lowercase.

    http://msdn.microsoft.com/en-us/library/windowsazure/dd135715.aspx

    Hope this helps.


    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, May 10, 2012 9:54 AM
    Moderator

All replies

  • Hi Srinath,

    I have moved this thread to a dedicated forum for better support.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 10, 2012 6:01 AM
  • This has been asked over on StackOverflow too, but it looks like the user has abandoned it: http://stackoverflow.com/questions/10497449/file-download-from-azure-blob

    No sense answering here.

    Thursday, May 10, 2012 9:39 AM
  • Hello,

    According to your description, you mentioned that "I have problem with .docx,.xlsx files and that too after deployment only, mean in local machine it is working fine." Is that mean the .docx and .xlsx files can be downloaded success in storage emulator (local SQL Server databse), but now works in Cloud Storage? or works fine at local machine with cloud Storage but not in cloud environment with cloud storage? And i suggest you provide more details about your exception message, such as Stack message or tracing logs.

    And please following Steve's suggestion check "blob.Properties.Length - 1" in HttpRequest Header.

    Here is the difference between Azure Cloud Storage and Azure Storage Emulator:

    http://msdn.microsoft.com/en-us/library/windowsazure/gg433135.aspx

    And i saw your blob container name is "ContainerName". is this a true container name or repalcer, if it's a ture container name will cause errors, Blob container name must be lowercase.

    http://msdn.microsoft.com/en-us/library/windowsazure/dd135715.aspx

    Hope this helps.


    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, May 10, 2012 9:54 AM
    Moderator
  • @Arwind, Thanks for your support, I followed steve marx instructions then it is fixed
    Thursday, June 7, 2012 8:07 AM