diff --git a/core/server/controllers/storage/localfilesystem.js b/core/server/controllers/storage/localfilesystem.js index 798e55cd9a..dcdf1fe855 100644 --- a/core/server/controllers/storage/localfilesystem.js +++ b/core/server/controllers/storage/localfilesystem.js @@ -58,24 +58,15 @@ localfilesystem = { getUniqueFileName(target_dir, basename, ext, null, function (filename) { - fs.mkdirs(target_dir, function (err) { - if (err) { - errors.logError(err); - return saved.reject(); - } - - fs.copy(image.path, target_path, function (err) { - if (err) { - errors.logError(err); - return saved.reject(); - } - - // NOTE as every upload will need to delete the tmp file make this the admin controllers job - - // The src for the image must be in URI format, not a file system path, which in Windows uses \ - var fullUrl = path.join(ghostUrl, filename).replace(new RegExp('\\' + path.sep, 'g'), '/'); - return saved.resolve(fullUrl); - }); + nodefn.call(fs.mkdirs, target_dir).then(function () { + return nodefn.call(fs.copy, image.path, target_path); + }).then(function () { + // The src for the image must be in URI format, not a file system path, which in Windows uses \ + var fullUrl = path.join(ghostUrl, filename).replace(new RegExp('\\' + path.sep, 'g'), '/'); + return saved.resolve(fullUrl); + }).otherwise(function (e) { + errors.logError(e); + return saved.reject(e); }); }); @@ -83,4 +74,4 @@ localfilesystem = { } }; -module.exports = localfilesystem; \ No newline at end of file +module.exports = localfilesystem;