Created
October 7, 2015 17:35
-
-
Save jjhiew/57499e1e076e3e157be8 to your computer and use it in GitHub Desktop.
Stream a PDF to S3 using HTML-PDF and Streaming S3 (NodeJS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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