Skip to content

upload file to qiniu plugin for egg-framework, based on qiniu node SDK

License

Notifications You must be signed in to change notification settings

Raoul1996/egg-qiniu-upload

Repository files navigation

egg-qiniu-upload

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-qiniu-upload --save

Usage

// {app_root}/config/plugin.js
exports.qiniu = {
  enable: true,
  package: 'egg-qiniu-upload',
};

Configuration

// {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

Example

upload file to qiniu and return the url and key

// {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'}
*/

get the file info by your file's key

// {app_root}/app/servcie/file.js
async info(key) {
  // your should auth the user's passport.
  return await this.app.qiniu.info(key);
}

more function ...

Questions & Suggestions

Please open an issue here.

License

MIT

About

upload file to qiniu plugin for egg-framework, based on qiniu node SDK

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published