【发布时间】:2017-08-03 10:27:46
【问题描述】:
我正在使用 Infragistics 报告系统将报告创建为 PDF 并将它们保存到 Azure Blob 存储,但我无法让它工作。我将报告生成为报告对象,没有任何问题。这个对象有一个名为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](HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase
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(RESTCommand1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx) 在 c:\Program Files ( x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:2339 行 在 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult) 在 c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 299 --- 内部异常堆栈跟踪结束 ---
有人有什么建议吗?
我在我的 blob 服务的构造函数上更新了我的连接代码,它现在看起来像这样,但它仍然不起作用,fiddler 给了我这个
连接本地主机:10000 HTTP/1.1 主机:本地主机:10000
HTTP/1.1 200 连接已建立 FiddlerGateway:直接 开始时间:14:23:33.061 连接:关闭 结束时间:14:23:33.063 客户端到服务器字节:125 服务器到客户端字节: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
});
}
}
【问题讨论】:
-
实际文件名是什么?另外,你吞下的有什么例外吗?
-
我看不到给它一个文件名,因为它应该直接流式传输到 azure 并在以后作为 pdf 取出。我根据 GUID 及其描述给它一个唯一的名称。没有产生异常
-
当唯一的错误消息是远程服务器返回错误:(400) 错误请求时,任何人都打算调试进程。 ?.现在完全被难住了
-
您是否尝试过在 Fiddler 中拦截调用 (zappysys.com/blog/…) 以分析来自 Azure 的响应?
-
couldn't get fiddler to intercept localhost,我用谷歌搜索了解决方案,但它们似乎都涉及更改 url,我不确定在本地使用 azure 时是否可行,我无法控制网址
标签: c# azure memorystream azure-blob-storage