我不得不从 Windows Azure 1.7 升级到 2.1。我唯一的代码更改
blob.UploadFromFile(tempImage); 到 blob.UploadFromFile(tempImage,FileMode.CreateNew);
但是我收到以下错误:“将 FileMode:CreateNew 与 FileAccess 结合:读取无效。”
下面是我的代码(我添加了“blob.OpenWrite();”只是为了尝试)。任何想法为什么我会收到此错误?
string blobUri;
/*var acct = CloudStorageAccount.FromConfigurationSetting("ImagesConnectionString");*/
var setting = CloudConfigurationManager.GetSetting("ImagesConnectionString");
var acct = CloudStorageAccount.Parse(setting);
var blobClient = acct.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName")); //.GetContainerReference("ContainerName");
container.CreateIfNotExists(); //CreateIfNotExist
var perms = container.GetPermissions();
//upload blob image
LocalResource local = RoleEnvironment.GetLocalResource("tempImages");
string tempSlideImage = local.RootPath + mySlideName;
myImage.Save(tempSlideImage);
CloudBlockBlob blob = container.GetBlockBlobReference(myImageName);
blob.Properties.ContentType = "image/jpeg"; //photoToLoad.PostedFile.ContentType; //blob.Properties.ContentType = photoToLoad.PostedFile.ContentType;
blobClient.ParallelOperationThreadCount = 3;
blob.OpenWrite(); //this was added after the migration
blob.UploadFromFile(tempImage,FileMode.CreateNew); //.UploadFile //blob.UploadFromStream(photoToLoad.FileContent);
blobUri = blob.Uri.ToString();