首页 > 解决方案 > 在上传到 AzureCloud BlobStorage 时为 UNIT_TESTCASE 命名一个异常

问题描述

在上传到 AzureCloud BlobStorage 时为 UNIT_TESTCASE 命名一个异常。

我的代码是,

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve a reference to a container.
 CloudBlobContainer container = 
 blobClient.GetContainerReference("myblogcontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = 
container.GetBlockBlobReference("WeekendChamps.jpg");

// Create or overwrite the "myblob" blob with contents from a local file.
 using (var fileStream = 
 System.IO.File.OpenRead(@"C:\Users\Bliss\Downloads\WeekendChamps.jpg"))
 {
 blockBlob.UploadFromStream(fileStream);
 }

标签: c#azureexceptionazure-blob-storage

解决方案


在 try catch 块中捕获StorageException,在 catch 块中您可以处理异常以获取 RequestInformation 和 StorageExtendedErrorInformation。

BlobErrorCodeStrings类中为 Blob 定义了各种异常代码。您可以对错误代码进行切换,也可以尝试匹配您需要的任何特定错误代码。


推荐阅读