创建 PDF 并将其上传到 Azure Blob 存储

发布于 2025-01-09 07:59:54 字数 424 浏览 4 评论 0原文

我正在使用 PDFkit 创建 PDF,但是我想将创建的 PDF 上传到 azure blob 存储。我有以下代码(打字稿),但它不起作用:

const doc = new PDFDocument();
doc.fontSize(27).text("test", 100, 100);
doc.end();

const uploadBlobResponse = await blockBlobClient.upload(
      doc,
      Buffer.byteLength(doc)
    );

我能够连接到azure blob存储,但是上传部分不起作用

I'm using PDFkit to create a PDF, however I want to upload the created PDF to azure blob storage. I have the below code (typescript) but its not working:

const doc = new PDFDocument();
doc.fontSize(27).text("test", 100, 100);
doc.end();

const uploadBlobResponse = await blockBlobClient.upload(
      doc,
      Buffer.byteLength(doc)
    );

i'm able to connect to the azure blob storage, however the uploading part is not working

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2025-01-16 07:59:54

我已经在我的环境中进行了测试

您可以使用以下代码将PDF文件从PDFKIT上传到Azure Blob存储

const PDFDocument = require('pdfkit');
const fs = require('fs');
const blobName = "doc.pdf";
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream(blobName));
doc.fontSize(27).text("test", 100, 100);
doc.end();

const uploadBlobResponse = await blockBlobClient.uploadFile(blobName);

I have tested in my environment

You can use the below code to upload PDF file from PDFKIT to Azure Blob Storage

const PDFDocument = require('pdfkit');
const fs = require('fs');
const blobName = "doc.pdf";
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream(blobName));
doc.fontSize(27).text("test", 100, 100);
doc.end();

const uploadBlobResponse = await blockBlobClient.uploadFile(blobName);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文