Skip to content

Instantly share code, notes, and snippets.

@jjhiew
Created October 7, 2015 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jjhiew/57499e1e076e3e157be8 to your computer and use it in GitHub Desktop.
Save jjhiew/57499e1e076e3e157be8 to your computer and use it in GitHub Desktop.
Stream a PDF to S3 using HTML-PDF and Streaming S3 (NodeJS)
var pdf = require('html-pdf');
var fs = require('fs');
var streamingS3 = require('streaming-s3') ;
var html = '<h1>Test</h1><p>Hello World</p>';
pdf.create(html).toStream(function(err, stream) {
var uploader = new streamingS3(stream {
accessKeyId: 'YOUR_ACCESS_KEY_ID',
secretAccessKey: 'YOUR_SECRET_ACCESS_KEY'
}, {
Bucket: 'test.bucket',
key: 'output.pdf',
ContentType: 'application/pdf'
}, function(err, resp, stats){
if (err) return console.log("Error uploading to S3: ", err);
console.log("Upload Stats: ", stats);
console.log("Upload Successful: ", resp);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment