I am wondering if there is an easy way to determine readStream length in node js. I am writing an employee to upload PDF files to S3, and it raises an error: "Unable to determine the length of [object PDFDocument]". PDF is a readable stream (I can transfer it to a file in memory at present and view the generated PDF file).
Some things I was thinking about: 1. Piping the entire pdf to memory (for example, to the buffer), and then fstat is called in this buffer to determine the size.
- Creating some method that dynamically found the size when I was passing the PDF through it.
Or is there an easier way? Open to all offers, thanks in advance!
Here is the S3 challenge. The readable PDF stream is called doc:
return Q.ninvoke(s3, 'putObject', {Bucket: 'REDACTED', Key: obfuscatedFN, Body: doc, ContentType: 'application/pdf'})
.then(function() {
console.log("Successfully uploaded data to myBucket/myKey");
return Q(true);
})
.fail(function(err) {
console.log(err);
})