[英]Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found
[英]Azure Worker role and blob storage c# - Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request
我已將文件上傳到Blob存儲中。 我正在嘗試從輔助角色下載這些文件以對其進行一些處理。 容器名稱從WebApi2發送到隊列。
worker角色首先從隊列中獲取容器名稱,然后嘗試下載該容器中的blob。
以下是名稱的代碼:
public override void Run()
{
Trace.WriteLine("Starting processing of messages");
// Initiates the message pump and callback is invoked for each message that is received, calling close on the client will stop the pump.
Client.OnMessage((receivedMessage) =>
{
try
{
// Process the message
Trace.WriteLine("Processing Service Bus message: " + receivedMessage.SequenceNumber.ToString());
string msg = "Container Name: " + receivedMessage.GetBody<String>();
Trace.WriteLine("Processing Service Bus message: " + msg);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("MyStorage"));
CloudBlobContainer imagesContainer = null;
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
imagesContainer = blobClient.GetContainerReference(msg);
// Create the container if it doesn't already exist.
imagesContainer.CreateIfNotExists();
imagesContainer.SetPermissions(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
var blobs = imagesContainer.ListBlobs();
var listOfFileNames = new List<string>();
foreach (var blob in blobs)
{
var blobFileName = blob.Uri.Segments.Last();
listOfFileNames.Add(blobFileName);
Trace.WriteLine(listOfFileNames);
}
if (listOfFileNames == null)
{
Trace.WriteLine("present");
}
for (i = 1; i < 3; i++)
{
CloudBlockBlob signBlob = imagesContainer.GetBlockBlobReference(i + ".txt");
MemoryStream lms = new MemoryStream();
signBlob.DownloadToStream(lms);
lms.Seek(0, SeekOrigin.Begin);
StreamReader SR = new StreamReader(lms);
Trace.WriteLine(SR);
}
}
catch(Microsoft.WindowsAzure.Storage.StorageException e)
{
// Handle any message processing specific exceptions here
Trace.WriteLine("Error:" + e);
}
});
CompletedEvent.WaitOne();
}
我收到以下異常:
enter code hereException thrown: 'Microsoft.WindowsAzure.Storage.StorageException' in Microsoft.WindowsAzure.Storage.dll
錯誤:Microsoft.WindowsAzure.Storage.StorageException:遠程服務器返回錯誤:(400)錯誤的請求。 ---> System.Net.WebException:遠程服務器返回錯誤:(400)錯誤的請求。 在System.Net.HttpWebRequest.GetResponse()在Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [T](RESTCommand 1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Executor\\Executor.cs:line 677 --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand
1 C:\\ Program Files(x86)\\ Jenkins \\ workspace \\ release_dotnet_master \\ Lib \\ ClassLibraryCommon \\ Core \\ Executor \\ Executor.cs:行604中的cmd,IRetryPolicy策略,OperationContext operationContext):Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists (C:\\ Program Files(x86)\\ Jenkins \\ workspace \\ release_dotnet_master \\ Lib \\ ClassLibraryCommon \\ Blob \\ CloudBlobContainer.cs:Line 199中的BlobContainerPublicAccessType accessType,BlobRequestOptions requestOptions,OperationContext operationContext):WorkerRoleWithSBQueue1.WorkerRole.bred_4_0上的199行 receiveMessage)
任何幫助將不勝感激。
查看您的代碼,您正在執行以下操作:
string msg = "Container Name: " + receivedMessage.GetBody<String>();
然后您要執行以下操作:
imagesContainer = blobClient.GetContainerReference(msg);
// Create the container if it doesn't already exist.
imagesContainer.CreateIfNotExists();
因此,基本上,您正在創建一個容器名稱,該名稱以“容器名稱”開頭,這是該Container Name
的無效值。 這就是為什么您得到錯誤。
請參閱此鏈接以獲取Blob容器的有效命名約定: https : //msdn.microsoft.com/zh-cn/library/azure/dd135715.aspx 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.