【发布时间】:2017-12-14 10:00:00
【问题描述】:
这是我的代码:
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using Microsoft.WindowsAzure;
using System.Net.Http;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//get the storage account from the connection string
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=[account name];AccountKey=[account key];EndpointSuffix=core.windows.net");
//instantiate the client
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//set the container
CloudBlobContainer container = blobClient.GetContainerReference("images");
//get the blob reference
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob.jpg");
//get image from stream and upload
using (var client = new HttpClient())
{
using (var stream = client.GetStreamAsync(some_url).GetAwaiter().GetResult())
{
if (stream != null)
{
blockBlob.UploadFromStreamAsync(stream);
}
}
client.Dispose();
}
}
}
}
存储帐户实例化工作正常。 容器引用工作正常(它实际上存在)。 块 blob 引用也可以正常工作,没有错误。 该流具有我从引用的 URL 获取的图像。 最后,上传没有返回错误。
除了,当我导航到 Blob URI 时没有图像。
我收到以下错误:
指定的 blob 不存在。 RequestId:7df0aadc-0001-007c-6b90-f95158000000 时间:2017-07-10T15:21:25.2984015Z
我还通过 Azure 门户上传了一张图片,该图片存在并且可以通过浏览器导航到。
我错过了什么吗?
【问题讨论】:
-
请尝试在上传前将流的位置设置为 0。
-
容器是公有的还是私有的?
-
您使用
GetAwaiter().GetResult()调用async方法,这是非常不好的做法。
标签: azure .net-core azure-storage azure-blob-storage