我必須從Windows Azure 1.7升級到2.1。我在代碼中的唯一變化是將文件上傳到CloudBlockBlob時出現訪問問題 - Windows Azure
blob.UploadFromFile(tempImage); 至 blob.UploadFromFile(tempImage,FileMode.CreateNew);
但是,我收到以下錯誤:「將FileMode:CreateNew與FileAccess:Read組合起來無效」。
這是我的代碼如下(我添加了「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();
非常感謝。你是正確的,它是tempslideimage。我真的通過使用流 – xmorera
謝謝!這也讓我受益匪淺。這是絕對沒有意義的,你必須指定FileMode參數 - 我什麼時候會希望它使用除FileMode.Read之外的任何東西 - 我只能想到只想上傳空文件的情況,然後我可以告訴它創建新的 –
更新:Azure SDK 2.7與.NET 4.5.1以下代碼工作blob.UploadFromFile(tempImage,FileMode.Open); – ProVega