Reputation: 310
I have a buffer returned by an API call containing file data however when I try to S3.Upload()
or fs.write()
the file is corrupt for anything except PDFs (png, jpg, .doc, .docx are the key types I need). For PDFs I just use the binary data as it comes in (fs.writeFile('myFile.docx', myBuffer)
) but I've also tried:
fs.writeFile('myFile.docx', myBuffer.toString('base64'))
, fs.writeFile('myFile.docx', myBuffer.toString('utf8'))
,fs.writeFile('myFile.docx', myBuffer.toString('binary'))
I'm sure it's to do with encoding the binary from the buffer but I've reached the limit of my knowledge with the above attempts.
Upvotes: 1
Views: 979
Reputation: 310
It turns out that my method for dividing the data stream was leaving a trailing /r/n
on the end of each file, PDFs don't seem to mind, everything else does.
Upvotes: 1