none
Blob download throws Transport connection closed exception

    Question

  • I am trying to download a blob from the blob storage. The blob is about 250 MB and is being downloaded as a stream. The code is given below

     public void BlobStreamDownload(string containerName, string blobName, string FileName)
            {
                
                CloudBlobContainer container = BlobClient.GetContainerReference(containerName);
                
                CloudBlob blob = container.GetBlockBlobReference(blobName);
                //blob.DownloadToFile(FileName); <- same error
                using (Stream file = File.Create(FileName))
                {
                    blob.DownloadToStream(file); /* I am using SDK v1.6 *.
                }
            }


    The exact exception message is "Unable to read data from the transport connection: The connection was closed". Where should I look for solution? Thank you.


    Dinesh Agarwal


    Tuesday, March 06, 2012 1:00 AM

Answers

  • Hi Dinesh -

    Actually, the most likely cause for this is the timeout.  By default, the download operations have a 90 second timeout.  If the blob hasn't completed downloading in that time, then this exception will be thrown.

    Create a BlobRequestOptions object like this (this one results in a 10 minute timeout - you should choose a time based on expected download rates and acceptable wait times):

    BlobRequestOptions options = new BlobRequestOptions();
    options.Timeout = new TimeSpan(0, 10, 0);

    And then pass it in to the Download method.  Hope that helps - if you increase this time, and you get the exception above in less time than the timeout specified, then there may be something else going on.

    -Jeff

    • Marked as answer by dinwal_pdc_guy Wednesday, March 07, 2012 11:10 PM
    Wednesday, March 07, 2012 5:50 PM

All replies

  • Hello.

    I think that this problem can occur when:

    1) nothing is here

    2) timeout

    Do you sure that your blob exist?

    Tuesday, March 06, 2012 4:18 AM
  • Yes, I am sure because in my app the list is populated with all the blobs that are present in the container. Also, I am able to download 2 MB files without any issue. It is only with larger files.


    Dinesh Agarwal


    Tuesday, March 06, 2012 4:43 AM
  • Hi,

    It may happened if your network connection is too slow (for example, download speed is less than 10 KB/s). If the network connection is fine, please try the download again. Please also check if your application/proxy/network has some limitations on the max response returned by a server.

    Best Regards,

    Ming Xu.


    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

    Tuesday, March 06, 2012 7:59 AM
    Moderator
  • I agree with Ming - what download speeds are you getting?  Are you able to task manager to see this?  It'd be great to know how much of the file is downloading before you hit this error, and whether that value is consistent on each attempt.


    -Jeff

    Tuesday, March 06, 2012 6:16 PM
  • Downloading speed is not an issue for sure. The net is about 100 MB/s at school. I use the API, how do I find out how much has been downloaded?

    Dinesh Agarwal

    Wednesday, March 07, 2012 6:17 AM
  • Hi Dinesh -

    Actually, the most likely cause for this is the timeout.  By default, the download operations have a 90 second timeout.  If the blob hasn't completed downloading in that time, then this exception will be thrown.

    Create a BlobRequestOptions object like this (this one results in a 10 minute timeout - you should choose a time based on expected download rates and acceptable wait times):

    BlobRequestOptions options = new BlobRequestOptions();
    options.Timeout = new TimeSpan(0, 10, 0);

    And then pass it in to the Download method.  Hope that helps - if you increase this time, and you get the exception above in less time than the timeout specified, then there may be something else going on.

    -Jeff

    • Marked as answer by dinwal_pdc_guy Wednesday, March 07, 2012 11:10 PM
    Wednesday, March 07, 2012 5:50 PM
  • Thank you Jeff. I will try it and let you know if I have further questions.

    Dinesh Agarwal

    Wednesday, March 07, 2012 11:10 PM
  • Hi I Think you should not download the BLOB as a whole.

    Try dividing the stream into diffrent chunks and then download.

    Best Regards,

    Brij Mohan

    Wednesday, May 02, 2012 10:16 AM