1

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]>>
Fred J.
  • 5,759
  • 10
  • 57
  • 106
  • have you tried setting `ContentType: 'application/pdf'` in your `s3.putObject()` call? EDIT: it seems like you want to use `s3.upload()` method instead. See https://stackoverflow.com/a/34298256/1799146 – julian soro Sep 01 '17 at 05:08
  • I just tried by adding `ContentType: 'application/pdf'` to the first arg. object of the `s3.putObject` but it did not work, still nothing in the download to my local machine. even it downloaded it to the s3 bucket. – Fred J. Sep 01 '17 at 05:13
  • Can you show the raw first 100 bytes or so of the original file, the s3 version, and the downloaded version? – Michel Floyd Sep 01 '17 at 07:27
  • @MichelFloyd I am not sure what you mean by "the s3 version". Please see the edit. – Fred J. Sep 01 '17 at 11:17
  • The file that is saved in s3. There are 2 places where you might have errors - the upload to s3 and of course the download to the browser. Looking to see how/where things got mangled. – Michel Floyd Sep 01 '17 at 16:49

0 Answers0