【发布时间】:2021-06-03 04:55:18
【问题描述】:
我正在尝试将图像上传到 Azure Blob 存储。我正在使用 .Net Core 和 Azure.Storage.Blobs v12.8.0。
以下代码是我目前所拥有的。
try
{
var documentByteArray = // a valid byte array of a png file
var blobUri = new Uri("https://mystorageaccount.blob.core.windows.net/images/myfile.png");
BlobClient blobClient = new BlobClient(blobUri);
using (MemoryStream stream = new MemoryStream(documentByteArray))
{
await blobClient.UploadAsync(stream, true, default);
await blobClient.SetHttpHeadersAsync(new BlobHttpHeaders
{
ContentType = "image/png"
});
}
}
catch (Exception ex)
{
//
}
...但在某种程度上可以预见它会失败,但 Server failed to authenticate the request. Please refer to the information in the www-authenticate header. 除外。我说可预测是因为我没有添加任何身份验证...
这就是问题/问题。如何添加身份验证以便上传?
我知道有可以使用的访问密钥 - 但如何使用?我在 MS 文档中找不到任何示例。
感谢任何见解。
【问题讨论】:
标签: c# azure authentication blob azure-storage