我有一个带有 blob 触发器的 azure 函数,我想在逻辑应用程序中使用它。然后我意识到逻辑应用程序只支持 HTTP 触发器 azure 函数。
我将在 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.
最佳答案
问题是在 Postman 中提交 pdf 的方式。 Binary
而不是 form-data
解决了这个问题。
关于c# - 在 Azure 函数中读取包含 pdf 的请求正文时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58338799/