我想先设置所有上传的blob的缓存控制属性,但是它会抛出异常"远程服务器返回错误:(404)Not Found。"
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
List<CloudBlobContainer> containers = blobClient.ListContainers().ToList();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
List<IListBlobItem> blobs = container.ListBlobs().ToList();
int count = 0;
foreach (IListBlobItem blob in blobs)
{
CloudBlockBlob b = container.GetBlockBlobReference(blob.Uri.ToString());
b.Properties.CacheControl = "public, max-age=1296000";
b.SetProperties();
Console.WriteLine("cached"+count.ToString());
count++;
}
SetProperties正在抛出错误。
答案 0 :(得分:0)
您正在进行分层列表,它可以返回虚拟目录以及blob。例如,如果您有一个名为“foo / bar”的blob,那么您的列表将返回名为“foo /”的CloudBlobDirectory。当您尝试将其用作blob名称时,该服务会重新生成404,因为blob不存在。
要完成您想要的任务,请将“useFlatBlobListing:true”传递给ListBlobs,然后将每个返回的IListBlobItem转换为CloudBlob。