cky-image-public
Version:
public image to public host
32 lines (25 loc) • 745 B
JavaScript
const fs = require("fs");
let log = require('debug')('CKY-IMAGE-PUBLIC').extend('FILESTACK');
let helper = require('../helper');
class Filestack {
constructor (options = {}) {
let { api_key } = options;
this.api_key = api_key;
this.client = require('filestack-js').init(api_key);
}
upload (imgPath, callback) {
if (!this.api_key) return callback('ENOAPIKEY', 'Invalid Api Key');
const onProgress = (evt) => {
log(`upload onProgress: ${evt.totalPercent}%`);
};
let token = {};
this.client.upload(imgPath, { onProgress }, {}, token)
.then((res) => {
return callback(null, res);
})
.catch(err => {
return callback(err);
});
}
}
module.exports = Filestack;