尝试写入Blob存储时出现Head 404依赖关系问题

时间:2019-02-27 08:25:28

标签: azure azure-storage-blobs

我在Blob内有存储空间,并可以公共访问。 但是当我尝试编写文档时,实时遥测显示在“依赖项错误”下面。

1:21:57 PM |依赖| 404 | 65岁 HEAD图像a | LogLevel =信息| Blob = 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 个答案:

答案 0 :(得分:1)

我无法在控制台应用中使用相同的代码重现您的问题(如果您在某些特殊设置/环境下运行代码,请指出来)

请确保以下几点:

1。检查是否在azure门户中将blob访问设置为public,并检查代码是否使用相同的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.
                }
            }

如果您还有其他问题,请告诉我。

相关问题