Node js, piping pdfkit to a memory stream

后端 未结 5 1560
谎友^
谎友^ 2021-02-07 21:07

I am using pdfkit (https://github.com/devongovett/pdfkit) on my node server, typically creating pdf files, and then uploading them to s3. The problem is that pdfkit examples pip

5条回答
  •  既然无缘
    2021-02-07 21:59

    You could try something like this, and upload it to S3 inside the end event.

    var doc = new pdfkit();
    
    var MemoryStream = require('memorystream');
    var memStream = new MemoryStream(null, {
       readable : false
    });
    
    doc.pipe(memStream);
    
    doc.on('end', function () {
       var buffer = Buffer.concat(memStream.queue);
       awsservice.putS3Object(buffer, fileName, fileType, folder).then(function () { }, reject);
    })
    

提交回复
热议问题