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