This commit is contained in:
Julian Lam
2016-02-09 09:45:11 -05:00
parent 2ce64726ba
commit 3a6ad52ac8
3 changed files with 16 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ var Jimp = require('jimp');
var db = require('../database');
var file = require('../file');
var uploadsController = require('../controllers/uploads');
module.exports = function(Groups) {
@@ -38,7 +39,11 @@ module.exports = function(Groups) {
writeImageDataToFile(data.imageData, next);
},
function (_tempPath, next) {
tempPath = _tempPath;
tempPath = _tempPath; // set in local var so it can be deleted if file type invalid
next(null, tempPath);
},
async.apply(file.isFileTypeAllowed),
function (_tempPath, next) {
uploadsController.uploadGroupCover(uid, {
name: 'groupCover',
path: tempPath
@@ -65,7 +70,9 @@ module.exports = function(Groups) {
}
], function (err) {
if (err) {
return callback(err);
return fs.unlink(tempPath, function(unlinkErr) {
callback(err); // send back original error
});
}
if (data.position) {