简体   繁体   English

使用 Microsoft Playwright 在 Azure Function Linux 消费计划中创建本地 PDF 文件

[英]Creating a local PDF file in Azure Function Linux consumption plan with Microsoft Playwright

I am using Microsoft Playwright in order to create a PDF from a remote website inside an Azure Function (HTTP trigger).我正在使用 Microsoft Playwright从 Azure 函数(HTTP 触发器)内的远程网站创建 PDF。 The method used is page.GetPdfAsync() that only handles a file path in order to create the generated PDF file.使用的方法是 page.GetPdfAsync() ,它只处理文件路径以创建生成的 PDF 文件。 I would like to store the file in an Azure Blob storage container but as the GetPdfAsync() method doesn't handle stream or Azure blob storage, I am trying to temporary store the generated file.我想将文件存储在 Azure Blob 存储容器中,但由于 GetPdfAsync() 方法不处理流或 Azure Blob 存储,我正在尝试临时存储生成的文件。 I tried to use different local folders such as /tmp or /local but each time I trigger the function I see an exception in the trace saying that the filesystem is read-only .我尝试使用不同的本地文件夹,例如/tmp/local但每次触发该函数时,我都会在跟踪中看到一个异常,指出文件系统是只读的

I read this blog post from Anthony Chu so it seems that Playwright is now supported on a Linux consumption plan but in the article the generated screenshot is directly sent back in the HTTP response and never not stored on the local disk.我读了Anthony Chu 的这篇博文,所以似乎现在 Linux 消费计划支持 Playwright,但在文章中,生成的屏幕截图直接在 HTTP 响应中发回,从未不存储在本地磁盘上。

For the coding environment, I am using C#, VS 2019 and Azure Function Core Tools + Azure CLI for the deployment.对于编码环境,我使用 C#、VS 2019 和 Azure Function Core Tools + Azure CLI 进行部署。

Any idea how I can handle this scenario?知道我如何处理这种情况吗?

Page.GetPdfAsync() returns a byte[] . Page.GetPdfAsync()返回一个byte[] You can pass null to the path and upload the resulting byte[] to Azure.您可以将 null 传递给路径并将生成的byte[]上传到 Azure。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM