gpt4 book ai didi

azure - 将文件上传到 CloudBlockBlob 时出现访问问题 - Windows Azure

转载 作者:行者123 更新时间:2023-12-01 19:45:27 24 4
gpt4 key购买 nike

我必须从 Windows Azure 1.7 升级到 2.1。我对代码的唯一更改

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

最佳答案

UploadFromFile 的第二个参数(FileMode)指的是您希望如何在本地计算机上打开文件,而不是您希望如何处理 Azure 存储中的 blob。因此,要修复您可以:

改变

blob.UploadFromFile(tempImage,FileMode.CreateNew); 

blob.UploadFromFile(tempImage,FileMode.Open); 

另外,tempImage是什么?您要么遗漏了这部分代码,要么它应该是 tempSlideImage。

关于azure - 将文件上传到 CloudBlockBlob 时出现访问问题 - Windows Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19552476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com