I am trying to save a PDF to S3 using the AWS-SDK. I receive a PDF through the body of the POST (application / PDF).
When saving the file in local HD with the fs.writeFile file, the file looks fine. But when loading into s3 the file is damaged (one white page pdf)
Welcome any help or hint!
var data = body // body from a POST request. var fileName = "test.pdf"; fs.writeFile(fileName, data, {encoding : "binary"}, function(err, data) { console.log('saved'); // File is OK! }); s3.putObject({ Bucket: "bucketName", Key: fileName, Body: data }, function(err, data) { console.log('uploaded') // File uploads incorrectly. });
EDIT:
It works if I write and then read the file and upload it.
fs.writeFile(fileName, data, {encoding : "binary"}, function(err, data) { fs.readFile(fileName, function(err, fileData) { s3.putObject({ Bucket: "bucketName", Key: fileName, Body: fileData }, function(err, data) { console.log('uploaded')
eddie source share