This Meteor server code tries to download a pdf file and save it in S3 bucket which it does but when I download it to my local machine to check, it does not open it. Any idea how to fix it? Thanks
let s3 = new AWS.S3();
HTTP.call('get', 'http://catalogue.pearsoned.co.uk/assets/hip/gb/hip_gb_pearsonhighered/samplechapter/1408278839.pdf', function (error, response) {
if (error || response.statusCode !== 200) {
console.log("failed to get image");
console.log(error);
} else {
s3.putObject({
Body: response.content,
Key: 'test.pdf',
Bucket: 'my-bucket-name'
}, function(error, data) {
if (error) {
console.log("error downloading image to s3");
} else {
console.log("success uploading to s3: " + JSON.stringify(data));
}
});
}
});
success uploading to s3: {"ETag":"\"31...7996c\""}
edit
using s3.upload
gave this output regardless of the ContentType: 'application/pdf'
presence.
success uploading to s3: {"ETag":"\"8...1\"","Location":"https://bucket-name.s3.amazonaws.com/test.pdf","key":"test.pdf","Key":"test.pdf","Bucket":"bucket-name"}
Now the file is present with it size in the bucket and it opens a pdf viewer but with blank pages.
edit 2
As requested by MichelFloyd in the comments:
// curl -O 'http://file-path.pdf then head -C 100 file.pdf
%????1.4
jearized 1/L 344505/O 94/E 109228/N 11/T 342618/H [ 976 747]>>
// Download from S3 to my local driver: then head -C 100 file.pdf
%����1.4
<</Linearized 1/L 344505/O 94/E 109228/N 11/T 342618/H [ 976 747]>>