2016-08-18 21:25:51 +02:00
|
|
|
var Promise = require('bluebird'),
|
2017-09-12 16:31:14 +01:00
|
|
|
fs = require('fs-extra'),
|
2017-05-15 19:52:01 +09:00
|
|
|
storage = require('../adapters/storage'),
|
2014-07-15 12:40:14 +02:00
|
|
|
upload;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ## Upload API Methods
|
|
|
|
*
|
2017-12-14 14:13:40 +01:00
|
|
|
* **See:** [API Methods](constants.js.html#api%20methods)
|
2014-07-15 12:40:14 +02:00
|
|
|
*/
|
|
|
|
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 12:40:14 +02: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 12:40:14 +02:00
|
|
|
// Remove uploaded file from tmp location
|
2017-12-13 20:03:07 +01:00
|
|
|
return fs.unlink(options.path);
|
2014-07-15 12:40:14 +02:00
|
|
|
});
|
2016-03-29 22:31:31 -05:00
|
|
|
})
|
2014-07-15 12:40:14 +02:00
|
|
|
};
|
|
|
|
|
2014-08-17 06:17:23 +00:00
|
|
|
module.exports = upload;
|