首先在我的web.config
我添加了代码:
<appSettings>
<add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
</appSettings>
我创建了容器,如您所见,它是公开的:
以及要上传的代码。相同的代码适用于 Azure 帐户,但不适用于模拟器!
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("imagesproducts");
var resultList = JsonConvert.DeserializeObject<List<string>>(Images);
var urlsList = new List<String>();
for(int i = 0; i < resultList.Count; i++)
{
byte[] singleImage = String.IsNullOrEmpty(resultList[i])? null : System.Convert.FromBase64String(resultList[i]);
CloudBlockBlob block = container.GetBlockBlobReference(Guid.NewGuid().ToString() + ".jpg");
using (var stream = new MemoryStream(singleImage, writable: false))
{
await block.UploadFromStreamAsync(stream);
}
urlsList.Add(block.Uri.AbsolutePath);
}
return JsonConvert.SerializeObject(urlsList);
而且我总是得到一个例外The remote server returned an error: (400) Bad Request
。