Last active
August 24, 2018 03:51
-
-
Save mervintankw/8752c1eb954c70a4b90d566c3954b78b to your computer and use it in GitHub Desktop.
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
//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