簡體   English   中英

發布到Azure Blob存儲時非常偶爾出現400錯誤的請求錯誤

[英]Very occasional 400 Bad Request error when posting to Azure Blob Storage

我正在使用Azure Blob存儲來緩存某些計算的中間結果。 一切都很好,除了極少數情況下,Azure Blob存儲客戶端返回如下錯誤:

The remote server returned an error: (400) Bad Request.

有問題的C#代碼如下所示:

public void Upload(string fileName, T entity)
{
    try
    {
        var blockBlob = _blobContainer.GetBlockBlobReference(fileName);
        using (var stream = _serializer.Serialize(entity))
        {
            blockBlob.UploadFromStream(stream);
        }
    }
    catch (Exception ex)
    {
        var json = JsonConvert.SerializeObject(entity).SubstringSafe(0, 500);
        _logger.Error("Error uploading object '{0}' of type '{1}' to blob storage container '{2}'; entity='{3}'; error={4}",
            fileName,
            typeof(T).Name,
            _containerName,
            json,
            ex.CompleteMessage());
        throw;
    }
}

fileName可能類似於“ 4110 \\ GetNodesForPathAnalysis”(在其他情況下可以使用),而_containerName可以是“ segmentedids”(在其他情況下也可以使用)。 我知道,此400錯誤的常見原因-引起了我幾次麻煩-是違反The Rules的容器或Blob名稱,但此處似乎並非如此。

錯誤是暫時性的-如果我刷新顯示該頁面的頁面,則該對象(具有相同的容器和文件名)將正確上載到Azure Blob存儲。

有什么建議么?

您可以按以下步驟設置BlobRequestOptions類詳細信息以及重試策略和超時-

//set the blob upload timeout and retry strategy
BlobRequestOptions options = new BlobRequestOptions();
options.ServerTimeout = new TimeSpan(0, 180, 0);
options.RetryPolicy = new ExponentialRetry(TimeSpan.Zero, 20);

然后,我們可以在PutBlock中指定此選項變量作為上載操作的一部分。 此處的詳細文章討論了如何創建要上傳的數據塊,然后以並行和異步方式將其上傳到Blob存儲。 鏈接在這里 -

http://sanganakauthority.blogspot.com/2014/07/upload-large-files-to-azure-block-blob.html

如果不需要異步,則可以使其同步。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM