const uploadFile = (remotePath, localFile) => new Promise((resolve, reject) => { upyun.uploadFile(remotePath, localFile, null, true, { 'x-gmkerl-thumbnail': 'default' }, (a, b) => { if (b.statusCode === 200) { resolve() } else { reject() } }) })
exports.uploadIMG = function(req, callback) { if(!req) return callback('not null'); if(!req.user_id) return callback('user_id not null'); if(!req.img) return callback('img not null'); var url = '/img/' + req.user_id + '/' + (+new Date()); upyun.uploadFile(url, './' + req.img.path, '', true, function (err, data) { data.url = url; var localFile = './' + req.img.path; if(fs.existsSync(localFile)) { fs.unlink(localFile, function(err) { callback(err, data); }); } }); }
function(data, next) { upyun.uploadFile('/qrcode/' + short_id, './qrcode-img/' + short_id + '.png', 'image/png', true, next); },