azure - 尝试写入 Blob 存储时出现 Head 404 依赖问题
问题描述
我有公共访问的存储和内部 Blob。但是当我尝试编写文档时,实时遥测显示在依赖错误下方。
下午 1 点 21 分 57 秒 | 依赖 | 404 | 65 头图像a| LogLevel=信息 | 斑点=255274.jpg
时间:下午 1 点 21 分 57 秒
持续时间:65 毫秒
传出命令:HEAD imagesa
结果代码:404
fileName =imageURL.Substring(imageURL.LastIndexOf(@"/") + 1);
var req = System.Net.WebRequest.Create(imageURL);
using (Stream filestream = req.GetResponse().GetResponseStream())
{
// Get the reference to the block blob from the container
CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(fileName);
//create a snapshot
bool existsTask = await blockBlob.ExistsAsync();
if (existsTask == true)
{
// the base blob's metadata is copied to the snapshot.
await blockBlob.CreateSnapshotAsync();
blockBlob.Metadata.Clear();
}
}
解决方案
我无法在控制台应用程序中使用相同的代码重现您的问题(如果您使用某些特殊设置/环境运行代码,请指出)。
请确保以下几点:
1.检查您是否已在 azure 门户中将 blob 访问权限设置为公共,并检查您的代码是否使用相同的 blob/容器。
2.请使用最新版本的WindowsAzure.Storage
软件包,9.3.3。
还有一件事你还需要知道:在代码之后blockBlob.Metadata.Clear()
,你需要使用blockBlob.SetMetadata()
。否则它不会清除元数据。
我使用的代码:
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("account", "key"), true);
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
var cloudBlobContainer = cloudBlobClient.GetContainerReference("test-2");
var imageURL = "https://xx.blob.core.windows.net/test-2/sample.JPG";
var fileName = imageURL.Substring(imageURL.LastIndexOf(@"/") + 1);
var req = System.Net.WebRequest.Create(imageURL);
using (Stream filestream = req.GetResponse().GetResponseStream())
{
CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference(fileName);
bool existsTask = await blockBlob.ExistsAsync();
if (existsTask == true)
{
await blockBlob.CreateSnapshotAsync();
blockBlob.Metadata.Clear();
blockBlob.SetMetadata(); // add this line of code to ensure the changes to metadata is committed.
}
}
如果您有更多问题,请告诉我。
推荐阅读
- c# - Asp.Net Core 2.1 中发生了什么变化,引入了一种模糊匹配来获取包含反射的方法
- java - 读取字符串列表中的名称
- python - 计算每行数据帧 A 出现在另一个数据帧中的许多元素的每一行中的次数
- python - asyncio.create_task 与等待
- python - AWS lambda Python期望','分隔符异常
- c++ - 如何在 UWP C# 中获取设备句柄以传递给 WriteFile
- javascript - 我尝试使用 p5.js 进行基于内核的图像处理
- scala - 在 ZIO 中,有没有办法将 IO[Nothing, T] 转换为 T,如果没有,为什么不呢?
- html - 布局:需要一个可以比同一行中的其他单元格更大的单元格
- google-chrome - 哪些辅助功能 API 可用于启用 Chrome 和 Firefox?UIA 效果不佳,经常中断