Azure函数中包含PDF的错误阅读请求正文

问题描述 投票:1回答:1

我想在Logic应用程序中使用带blob触发器的azure函数。然后,我意识到Logic应用程序仅支持HTTP触发天蓝色函数。

我将在Blob触发函数中正常运行的代码迁移到了新的http触发的Azure函数。我将blob触发函数中收到的流替换为http触发的请求体中的请求主体,但是无法打开用该流创建的pdf。

Blob触发功能

public static void Run([BlobTrigger("attachments/{name}", Connection = "")]Stream blobPdf, string name, ILogger log)
{
    // Create MemoryStream
    var streamPdf = new MemoryStream();
    CopyStream(blobPdf, streamPdf);
    // Create PDF from MemoryStream
    var pdf = PdfReader.Open(streamPdf);
}

HTTP触发功能

public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
        // Create MemoryStream
        var streamPdf = new MemoryStream();
        CopyStream(req.Body, streamPdf);
        // Create PDF from MemoryStream
        var pdf = PdfReader.Open(streamPdf);
}

尝试在最后一行打开pdf时弹出错误。根据pdf文件,有2个错误。第一个是:

System.Private.CoreLib: Exception while executing function: ExtractTextFromPDF. PdfSharp: Invalid PDF file: no trailer found.

第二个是:

System.Private.CoreLib: Exception while executing function: ExtractTextFromPDF. PdfSharp: Unexpected token 'n' in PDF stream. The file may be corrupted. If you think this is a bug in PDFsharp, please send us your PDF file.
c# http blob azure-functions
1个回答
0
投票

问题是在Postman中提交pdf的方式。 Binary代替了form-data解决了该问题。

© www.soinside.com 2019 - 2024. All rights reserved.