Search code examples
pdf-generationazure-storage

unable to upload file through storage


I am following this document for pdfkit. i have installed and created into pdf but when I attempted to upload my created files to azure blob storage, it returns an error.

An error message appears using JavaScript.

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

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

Pdfkit is a medium active ecosystem, and I am using latest version of pdfkit only.


Solution

  • I have tried to reproduce in my environment i am getting the result successfully. To upload a PDF file, please use the code provided below.

    const PDFDocument = require('pdfkit');
    const fs = require('fs');
    const blobName = "imran.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);
    

    enter image description here