当试图写入BLOB存储时,Head 404依赖关系问题



我有存储空间和内部blob,并具有公共访问权限。但是,当我试图编写文档实时遥测时显示下面的依赖项错误。

1:21:57 pm |依赖性|404 |65头部图像|loglevel =信息|blob = 255274.jpg

时间:1:21:57 pm

持续时间:65 ms

传出命令:头部图像

结果代码: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 Portal中将Blob访问设置为公共访问权限,并检查您的代码,如果使用相同的Blob/Container。

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.
                }
            }

如果您还有更多问题,请告诉我。

最新更新