locked
UploadFromStream No Longer Works After Porting to MVC4 - Pointers? RRS feed

  • Question

  • Updated my MVC3/.Net 4.5/Azure solution to MVC4.  My code for uploading an image to blob storage appears to fail each time in the upgraded MVC4 solution.  However, when I run my MVC3 solution works fine.  Code that does the uploading, in a DLL, has not changed.

    I’ve uploaded the same image file in the MVC3 and MVC4 solution.  I’ve inspected in the stream and it appears to be fine.  In both instance I am running the code locally on my machine and my connections point to blob storage in cloud.

    Any pointers for debugging?  Any known issues that I may not be aware of when upgrading to MVC4?

    Here is my upload code:

            public string AddImage(string pathName, string fileName, Stream image)
            {
                var client = _storageAccount.CreateCloudBlobClient();
                client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5));
                var container = client.GetContainerReference(AzureStorageNames.ImagesBlobContainerName);
    
                image.Seek(0, SeekOrigin.Begin);
                var blob = container.GetBlobReference(Path.Combine(pathName, fileName));
                blob.Properties.ContentType = "image/jpeg";
    
                blob.UploadFromStream(image);
    
                return blob.Uri.ToString();
            }
    New information:
    It appears that in MVC3 Path.Combine generates "foo\bar.jpg" and in MVC4 Path.Combine generates "foo\\bar.jpg".  As a result, GetBlobReference is escaping the "\\" generating a blob uri which in my case is not valid.  Both my MVC3 and MVC4 solution uses .NET 4.5 - nothing there changed.  Any suggestions?
    • Edited by boingo Friday, February 15, 2013 1:18 PM
    Friday, February 15, 2013 4:43 AM

Answers