Я загрузил файлы в хранилище blob. Я пытаюсь загрузить эти файлы из рабочей роли, чтобы выполнить некоторую обработку. Имя контейнера отправляется из WebApi2 в очередь.Роль Azure Worker и хранилище blob C# - Microsoft.WindowsAzure.Storage.StorageException: Удаленный сервер возвратил ошибку: (400) Неверный запрос
Роль рабочего сначала извлекает имя контейнера из очереди, а затем пытается загрузить капли в этом контейнере.
Ниже приведен код для имени:
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 cmd, политика IRetryPolicy, операцияContext operationContext) в c: \ Program Files (x86) \ Jenkins \ workspace \ release_dotnet_master \ Lib \ ClassLibraryCommon \ Core \ Executor \ Executor.cs: строка 604 в Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists (BlobContainerPublicAccessType accessType, BlobRequestOptions requestOptions, OperationContext operationContext) в c: \ Program Files (x86) \ Дженкинс \ рабочей \ release_dotnet_master \ Lib \ ClassLibraryCommon \ Blob \ CloudBlobContainer.cs: строка 199 в WorkerRoleWithSBQueue1.WorkerRole.b__4_0 (BrokeredMessage receivedMessage)
Любая помощь будет высоко оценили.
Какое имя контейнера вы пытаетесь создать? 400 во время создания контейнера обычно указывает недопустимое имя для контейнера. –
Можете ли вы получить доступ к какому-либо блоку из контейнера через общедоступный http-url? –