2016-08-18 14:25:51 -05:00
|
|
|
var Promise = require('bluebird'),
|
2014-07-15 05:40:14 -05:00
|
|
|
fs = require('fs-extra'),
|
2016-03-29 22:31:31 -05:00
|
|
|
pUnlink = Promise.promisify(fs.unlink),
|
2014-07-15 05:40:14 -05:00
|
|
|
storage = require('../storage'),
|
|
|
|
upload;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ## Upload API Methods
|
|
|
|
*
|
|
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
|
|
*/
|
|
|
|
upload = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Add Image
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @param {{context}} options
|
2016-03-29 22:31:31 -05:00
|
|
|
* @returns {Promise<String>} location of uploaded file
|
2014-07-15 05:40:14 -05:00
|
|
|
*/
|
2016-03-29 22:31:31 -05:00
|
|
|
add: Promise.method(function (options) {
|
|
|
|
var store = storage.getStorage();
|
|
|
|
|
|
|
|
return store.save(options).finally(function () {
|
2014-07-15 05:40:14 -05:00
|
|
|
// Remove uploaded file from tmp location
|
2016-03-29 22:31:31 -05:00
|
|
|
return pUnlink(options.path);
|
2014-07-15 05:40:14 -05:00
|
|
|
});
|
2016-03-29 22:31:31 -05:00
|
|
|
})
|
2014-07-15 05:40:14 -05:00
|
|
|
};
|
|
|
|
|
2014-08-17 01:17:23 -05:00
|
|
|
module.exports = upload;
|