Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mervintankw/8752c1eb954c70a4b90d566c3954b78b to your computer and use it in GitHub Desktop.
Save mervintankw/8752c1eb954c70a4b90d566c3954b78b to your computer and use it in GitHub Desktop.
//Create a local writestream
var wstream = fs.createWriteStream(tempFile, { encoding: 'binary' });
//Data has been written successfully
wstream.on('finish', function() {
fs.readFile(tempFile, function (err, fsData) {
// trigger upload to S3 function
uploadToS3(req, {
s3Path: s3Path,
contentType: data.mime_type,
buffer: fsData
}, function (status, url) {
data.url = '/' + data.url;
fs.unlink(tempFile, function(err) {});
callback();
});
});
});
wstream.on('error', function(err) {
logErr(req, 'createUpdateAttachment: download data writing failed', [err]);
wstream.close();
});
attachment.getContent(wstream)
.catch(function(err) {
logErr(req, 'createUpdateAttachment: caught error during data writing', [err]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment