none
Azure Blob download(GET) causes failed PUT request

    Question

  •     

    I'm downloading files from the Azure blob to display them to my users. The files are just resumes in doc/docx/pdf format. This used to work until few days ago, and only thing I did was update Azure SDK, so it might be the reason.
    Method is called from client-side, which ends up calling a method like this:

    CloudBlobContainer container = GetContainer(containerName);
    CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
    blockBlob.Properties.ContentType = contentType;
    
    using (var fileStream = new MemoryStream())
    {
    	await blockBlob.DownloadToStreamAsync(fileStream);
    	return fileStream;
    }


    GetContainer method is defined as follows:

        try
        {
            var storageAccount = StorageAccount;
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(containerName);
    
            if (container.CreateIfNotExists())
            {
                container.SetPermissions(new BlobContainerPermissions
                {
                     PublicAccess = BlobContainerPublicAccessType.Blob
                });
            }
            return container;
        }




    As of yesterday, I keep seeing in Azure Application Insights failed dependency calls. Not errors, just failed dependencies. Every time the file is downloaded, GET request is executed, but at the same time PUT request is also executed for some reason, and it fails.
    In the image below, you can see the Insights log for this error. Each one looks the same. The method is called, file downloaded and then that PUT request being called...



    Why is this PUT request being created, and how to solve this behavior, it's driving me crazy. What's also interesting is that everything works fine, as far as I can see, and this is happening with all my upload and download calls to blobs.


    Wednesday, January 11, 2017 4:27 PM

Answers

  • Good people from MS answered this question on Stackoverflow

    In short:

    As mentioned in the release notes about Microsoft Azure Storage Libraries for .NET for version 8.0.0:

    CreateIfNotExists methods will now only do one REST call instead of two.

    ...this issue dues to the changes of the Microsoft Azure Storage Libraries for .NET under the specific version. You could invoke CloudBlobContainer.Exist(), then call CloudBlobContainer.Create() instead of CloudBlobContainer.CreateIfNotExists. But at this point, you need to wrap CloudBlobContainer.Create() with try-catch to capture exceptions (e.g. someone has created the resource with the same name,etc.) by yourself.

     
    • Marked as answer by Nikola Biondic Thursday, January 12, 2017 8:35 AM
    Thursday, January 12, 2017 8:35 AM