amazon web services - PDF uploading to AWS S3 corrupted -


i managed generated pdf uploaded s3 node js server. pdf looks okay on local folder when tried access aws console, indicates "failed load pdf document".

i have tried uploading via s3.upload , s3.putobject apis, (for putobject used .on finish checker ensure file has been loaded before sending request). file in s3 bucket still same (small) size, 26 bytes , cannot loaded. appreciated!!!

    var pdfdoc = printer.createpdfkitdocument(inspectionreport);     var writestream = fs.createwritestream('pdfs/inspectionreport.pdf');     pdfdoc.pipe(writestream);     pdfdoc.end();     writestream.on('finish', function(){         const s3 = new aws.s3();         aws.config.loadfrompath('./modules/awsconfig.json');      var s3params = {         bucket: s3_bucket,         key: 'insp_report_test.pdf',         body: '/pdf/inspectionreport.pdf',         expires: 60,         contenttype: 'application/pdf'     };     s3.putobject(s3params, function(err,res){         if(err)              console.log(err);         else             console.log(res);     }) 

i realised pdfdoc.end() must come before piping starts. have used callback ensure s3 upload called after pdf write finished. see code below, hope helps!

var pdfdoc = printer.createpdfkitdocument(inspectionreport); pdfdoc.end();      async.parallel([          function(callback){             var writestream = fs.createwritestream('pdfs/inspectionreport.pdf');             pdfdoc.pipe(writestream);             console.log('pdf write finished!');             callback();         }      ], function(err){          const s3 = new aws.s3();         var s3params = {             bucket: s3_bucket,             key: 'insp_report_test.pdf',             body: pdfdoc,             expires: 60,             contenttype: 'application/pdf'         };          s3.upload(s3params, function(err,result){             if(err) console.log(err);             else console.log(result);         });     } ); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -