Commit 0e2645e0 authored by Cory Bryant's avatar Cory Bryant

Fix error with ON events and creating streams

parent 0341a89b
......@@ -33,7 +33,9 @@ module.exports=function s3BackedRenditions(config, $){
Key: params.renditionPath
}).on("httpHeaders", (statusCode, headers)=>{
lastModifiedTime = Date.parse(headers["last-modified"])
}).on("success", function(response) {
}).on("httpData", function(chunk) {
localFile.write(chunk);
}).on("httpDone", function(response) {
localFile.end();
if(lastModifiedTime){
fs.utimes(params.renditionPathOnDisk, lastModifiedTime, lastModifiedTime, ()=>{
......@@ -59,14 +61,13 @@ module.exports=function s3BackedRenditions(config, $){
localFile.end();
cb(msg);
}).createReadStream().pipe(localFile);
}).send();
},
/////////////////////////////////////////////////////////////////////////////
uploadRendition: (params)=>{
log.info("Uploading rendition " + params);
var localFile = fs.createReadStream(params.renditionPathOnDisk);
localFile.on('error', function(err) {
var msg = `Unable to access ${params.renditionPathOnDisk}`;
......@@ -74,21 +75,21 @@ module.exports=function s3BackedRenditions(config, $){
emailErrorOccasionally(params.emailError, msg);
});
var uploader = s3client.putObject({
var uploader = s3client.upload({
Body: localFile,
Bucket: s3conf.bucket,
Key: params.renditionPath
});
uploader.on("error", function(err){
localFile.end();
// localFile.end();
var msg = `Error uploading rendition to S3 bucket ${s3conf.bucket}. Please check config at: ${confPath}`;
log.error(msg, err);
emailErrorOccasionally(params.emailError, msg);
});
uploader.on("success", function(err){
localFile.end();
// localFile.end();
});
uploader.send();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment