Asp.net mvc 4 WindowsAzure UploadFromStream在移植到MVC4指针后不再工作?

Asp.net mvc 4 WindowsAzure UploadFromStream在移植到MVC4指针后不再工作?,asp.net-mvc-4,azure-storage,Asp.net Mvc 4,Azure Storage,将我的MVC3/.Net 4.5/Azure解决方案更新为MVC4。 在升级的MVC4解决方案中,每次我将图像上载到blob存储的代码似乎都会失败。但是,当我运行MVC3解决方案时,效果很好。在DLL中进行上载的代码没有更改 我在MVC3和MVC4解决方案中上传了相同的图像文件。我在溪流中检查过,看起来不错。在这两种情况下,我都在我的机器上本地运行代码,并且我的连接指向云中的blob存储 有调试的指针吗?升级到MVC4时我可能不知道的任何已知问题? 这是我的上传代码: publi

将我的MVC3/.Net 4.5/Azure解决方案更新为MVC4。 在升级的MVC4解决方案中,每次我将图像上载到blob存储的代码似乎都会失败。但是,当我运行MVC3解决方案时,效果很好。在DLL中进行上载的代码没有更改

我在MVC3和MVC4解决方案中上传了相同的图像文件。我在溪流中检查过,看起来不错。在这两种情况下,我都在我的机器上本地运行代码,并且我的连接指向云中的blob存储

有调试的指针吗?升级到MVC4时我可能不知道的任何已知问题? 这是我的上传代码:

        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();
    }

我设法把它修好了。由于某种原因,直接从HttpPostFileBase读取流无法工作。只需将其复制到一个新的内存流中即可解决它。 我的代码

public string StoreImage(string album, HttpPostedFileBase image)
    {   
        var blobStorage = storageAccount.CreateCloudBlobClient();
        var container = blobStorage.GetContainerReference("containerName");
        if (container.CreateIfNotExist())
        {
            // configure container for public access
            var permissions = container.GetPermissions();
            permissions.PublicAccess = BlobContainerPublicAccessType.Container;
            container.SetPermissions(permissions);
        }

        string uniqueBlobName = string.Format("{0}{1}", Guid.NewGuid().ToString(), Path.GetExtension(image.FileName)).ToLowerInvariant();
        CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
        blob.Properties.ContentType = image.ContentType;
        image.InputStream.Position = 0;
        using (var imageStream = new MemoryStream())
        {
            image.InputStream.CopyTo(imageStream);
            imageStream.Position = 0;
            blob.UploadFromStream(imageStream);
        }

        return blob.Uri.ToString();           
    }