并行斑点上传抛404错误的请求间歇 [英] Parallel Blob Upload throwing 404 Bad Request intermittently
问题描述
我有一个非常简单的服务,
I have a very simple service,
public class AzureService : IAzureService
{
private readonly CloudBlobContainer _container;
public AzureService(ISettings settings)
{
var storageAccount = CloudStorageAccount.Parse(settings.BlobConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
_container = blobClient.GetContainerReference(settings.BlobContainerName);
}
public Task UploadBlobAsync(string fileName, Stream stream)
{
var blob = _container.GetBlockBlobReference(fileName);
return blob.UploadFromStreamAsync(stream);
}
public Task DeleteBlobAsync(string fileName)
{
var blob = _container.GetBlockBlobReference(fileName);
return blob.DeleteAsync();
}
}
这个方法是从所谓的,
public Task SaveAllAsync(Dictionary<string, Stream> images)
{
var tasks = new List<Task>();
foreach (var image in images)
{
var fileName = image.Key;
var stream = image.Value;
var task = _azureService.UploadBlobAsync(fileName, stream);
tasks.Add(task);
}
return Task.WhenAll(tasks);
}
我流是<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httppostedfilebase.inputstream%28v=vs.110%29.aspx\">HttpPostedFileBase.InputStream.有时工作,有时我得到远程服务器返回错误:(400)错误的请求
。如果我把一个破发点时,它的工作原理也是如此。
My stream is HttpPostedFileBase.InputStream. Sometimes it works and sometimes I get The remote server returned an error: (400) Bad Request.
. If I put a break-point it works as well.
推荐答案
我有同样的问题,我想在1罢工上传20 +图像,单线程的作品,使用等待任务多线程。 WhenAll
失败,远程服务器返回错误:(400)错误的请求
I had the same problem , I tried to upload 20 + images in 1 strike , single threaded works , multi threaded using await Task.WhenAll
failed with "The remote server returned an error: (400) Bad Request."
-
看
RequestInformation
在Microsoft.WindowsAzure.Storage.StorageException
这是从上传抛出[XXX]异步方法更详细的信息。
see
RequestInformation
insideMicrosoft.WindowsAzure.Storage.StorageException
which is thrown from Upload[xxx]Async methods for more detailed information.
首先, RequestInformation
说了一些关于一个MD5问题Md5Mismatch的错误code,买我的直觉,否则表示,由于单个线程的工作方式类似魅力,然后..我发现... DefaultRequestOptions.ParallelOperationThreadCount
在 CloudBlobClient
对象和问题sovled。
At first , RequestInformation
said something about a MD5 problem with error code of "Md5Mismatch" , buy my intuition said otherwise because single thread works like a charm , and then .. I found it... DefaultRequestOptions.ParallelOperationThreadCount
on CloudBlobClient
object and problem sovled.
<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.blobrequestoptions_members.aspx\"相对=nofollow> BlobRequestOptions成员MSDN
private CloudBlobContainer ConnectToImageContainer()
{
var credentials = new StorageCredentials(AccountName, ImagesContainerKey);
var account = new CloudStorageAccount(credentials, useHttps: true);
var client = account.CreateCloudBlobClient();
client.DefaultRequestOptions.ParallelOperationThreadCount = 64; // max value
client.DefaultRequestOptions.SingleBlobUploadThresholdInBytes = 67108864; // max value
var container = client.GetContainerReference(ImagesContainerName);
return container;
}
这篇关于并行斑点上传抛404错误的请求间歇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!