All CDN/OSS upload providers in one command.
# npm
npm i -g filefly
# yarn
yarn global add filefly
# upload file to Aliyun OSS
filefly aliyun demo.jpg
# upload file to qiniu
filefly qiniu demo.jpg
# open config file
filefly config
Use $ filefly config
to open the config.json
folder:
// config.json
{
"aliyun": {
"accessKeyId": "",
"accessKeySecret": "",
"customDomains": [
"https://xxx.com",
]
}
}
# npm
npm i filefly
# yarn
yarn add filefly
import { Aliyun } from 'filefly'
const aliyun = new Aliyun(process.env.ALIYUN_ID, process.env.ALIYUN_SECRET)
// You'll be asked for which Bucket to choose, what custom domain is, or custom upload bucket path
const { rawUrl, customUrl } = await aliyun.upload(path.resolve(__dirname, 'demo.jpg'))
const aliyun = new Aliyun(process.env.TEST_ALIYUN_ID, process.env.TEST_ALIYUN_SECRET, {
// must set bucket name and region first
bucketName: '',
region: ''
})
const { rawUrl, customUrl } = await aliyun.uploadToBucket(path.resolve(__dirname, './demo.jpg'), {
bucketPath: 'path/to',
customDomain: 'https://assets.xxx.com'
})
- Aliyun
- qiniu
- AWS S3
MIT License