簡體   English   中英

將MemoryStream保存到Azure Blob存儲

[英]Saving a MemoryStream to Azure blob storage

我正在使用Infragistics報表系統將報表創建為PDF,並將其保存到Azure Blob存儲中,但是無法正常工作。 我將報告生成為Report對象,沒有任何問題。 此對象具有一種稱為Publish的方法,該方法將報告以指定的文件格式Publish到流中,在我的情況下為PDF。 當代碼嘗試從流中上傳時,出現此錯誤

Microsoft.WindowsAzure.Storage.StorageException:遠程服務器返回錯誤:(400)錯誤的請求

我不知道是什么原因造成的,錯誤消息實際上並沒有給我太多工作。 我在開發時使用的是本地存儲,這一切似乎都很好(我可以存儲圖像而沒有任何問題)。 這是崩潰的方法

public async Task<CloudBlockBlob> UploadAndSaveReportAsPDFToBlobAsync(Report report, EnumHelper.Reports reportName, string containerName)
{
    chpBlobContainer = blobClient.GetContainerReference(containerName);
    string blobName = Guid.NewGuid().ToString() + Path.GetExtension(reportName.GetDescription());
    // Retrieve reference to a blob. 
    CloudBlockBlob reportBlob = chpBlobContainer.GetBlockBlobReference(blobName);
    using (Stream stream = new MemoryStream())
    {
        try
        {
            report.Publish(stream, FileFormat.PDF);
        }
        catch(Exception ex)
        {
            //
        }

        await reportBlob.UploadFromStreamAsync(stream);
    }
    return reportBlob;
}

這是更多的錯誤消息

執行功能時發生異常:Functions.ProcessQueueMessage Microsoft.Azure.WebJobs.Host.FunctionInvocationException:執行功能時發生異常:Functions.ProcessQueueMessage ---> Microsoft.WindowsAzure.Storage.StorageException:遠程服務器返回錯誤:(400)錯誤請求。 ---> System.Net.WebException:遠程服務器返回錯誤:(400)錯誤的請求。 在Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException [T]( 1 cmd, Exception ex) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\Common\\Shared\\Protocol\\HttpResponseParsers.Common.cs:line 50 at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.<>c__DisplayClass42.<PutBlobImpl>b__41(RESTCommand c:\\ Program Files(x86)\\ Jenkins \\ workspace \\ release_dotnet_master \\ Lib \\ ClassLibraryCommon \\ Blob \\ CloudBlockBlob.cs:Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse [T](IAsyncResult getResponseResult)中的第2339行:\\ Program Files(x86)\\ Jenkins \\ workspace \\ release_dotnet_master \\ Lib \\ ClassLibraryCommon \\ Core \\ Executor \\ Executor.cs:第299行---內部異常堆棧跟蹤的結尾---

有人有什么建議嗎?

我已經在blob服務的構造函數上更新了連接代碼,現在看起來像這樣,但是仍然無法正常工作,而且提琴手給了我這個

CONNECT本地主機:10000 HTTP / 1.1主機:本地主機:10000

HTTP / 1.1 200建立的FiddlerGateway:直接開始時間:14:23:33.061連接:close結束時間:14:23:33.063 ClientToServerBytes:125 ServerToClientBytes:505

但它的http,我的連接指定了https,我仍然沒有一個明智的選擇

public BlobService()
    {
        var storageCredentials = new StorageCredentials("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");
        var blobEndpoint = new Uri("https://localhost.fiddler:10000");
        var queueEndpoint = new Uri("https://localhost.fiddler:10001");
        var tableEndpoint = new Uri("https://localhost.fiddler:10002");
        var storageAccount = new CloudStorageAccount(storageCredentials, blobEndpoint, queueEndpoint, tableEndpoint, null);
        var blobClient = storageAccount.CreateCloudBlobClient();
        chpBlobContainer = blobClient.GetContainerReference("CHPReports");
        if (chpBlobContainer.CreateIfNotExists())
        {
            // Enable public access on the newly created "images" container.
            chpBlobContainer.SetPermissions(
                new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });
        }
    }

您不能將“ CHPReports”用作容器名稱,因為名稱必須為小寫。

確保容器名稱有效

容器名稱必須是有效的DNS名稱,並符合以下命名規則:容器名稱必須以字母或數字開頭,並且只能包含字母,數字和破折號(-)字符。 每個破折號(-)必須緊跟在字母或數字之后; 容器名稱中不允許使用連續的破折號。 容器名稱中的所有字母都必須小寫。 容器名稱的長度必須在3到63個字符之間。

暫無
暫無

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

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