$ npm i egg-qiniu-upload --save
// {app_root}/config/plugin.js
exports.qiniu = {
enable: true,
package: 'egg-qiniu-upload',
};
// {app_root}/config/config.default.js
exports.qiniu = {
// I ussually set the key into `~/.zshrc`, and I can get the value via `process.env.key`, It's very safe~
ak: 'your access key',
sk: 'your secret key',
bucket: 'yout bucket',
baseUrl: 'your base url',
zone: 'your zone',
app: true, // default value
agent: false, //default value
};
see config/config.default.js for more detail, and more detail about qiniu please see the document
// {app_root}/app/service/file.js
async upload2Qiniu(path,realname) {
const {app} = this
// do someting what you want to do........
return await app.qiniu.upload(path, realname)
}
/* return a Objet:
{key:'your key',url:'your public url'}
*/
// {app_root}/app/servcie/file.js
async info(key) {
// your should auth the user's passport.
return await this.app.qiniu.info(key);
}
Please open an issue here.