upimg
v0.5.3
Published
image upload api
Readme
Usage
Installation
npm install upimgor
yarn add upimgRequire module
const upimg = require('upimg')Support servers
|server|endpoint|auth|url|status| |:---:|:---:|:---:|---|---| |58|58 同城|-|pic3.58cdn.com.cn|| |alibaba|aliexpress|-|ae01.alicdn.com|| |baidu|百度百家号|-|pic.rmb.bdstatic.com|| |jd|京东|-|img14.360buyimg.com|| |netease|网易严选|-|yanxuan.nosdn.127.net|失效| |suning|苏宁易购|-|image.suning.cn|失效| |toutiao|今日头条|-|p.pstatp.com|失效| |xiaomi|小米有品|-|shop.io.mi-img.com|失效| |xiaoyuzhou|小宇宙|-|image.xyzcdn.net|| |xitu|掘金|-|user-gold-cdn.xitu.io|失效| |bilibili|哔哩哔哩|cookie|i0.hdslb.com|| |qcloud|云+社区|cookie|ask.qcloudimg.com|| |qiniu|七牛云|cookie|dn-odum9helk.qbox.me|| |ximalaya|喜马拉雅|cookie|fdfs.xmcdn.com||
Upload file
take alibaba for example
upimg.alibaba
.upload('./test/nodejs.png')
.then(json => console.log(json))
.catch(err => console.error(err.message))success response
{
"success": true,
"message": "success",
"url": "https://ae01.alicdn.com/kf/HTB1dYeZXZrrK1RjSspa763REXXaP.png",
"type": {
"ext": "png",
"mime": "image/png"
}
}take qcloud for cookies required example
upimg.qcloud
.set('cookie', 'foo=bar; xxx=123')
.upload('./test/nodejs.png')
.then(json => console.log(json))
.catch(err => console.error(err.message))success response
{
"success": true,
"message": "success",
"url": "https://ask.qcloudimg.com/draft/1134330/g2oaa9bdbx.png",
"type": {
"ext": "png",
"mime": "image/png"
}
}API
upimg[server]
Returns an class with function:
set(key, value)- set optionsupload(image)- upload image
Or undefined when there is no server match.
.set(key, value)
Sets options[key] to value.
Returns a Promise which resolves self.
.upload(image)
Upload image to CDN server.
Returns a Promise which resolves upload result.
- success:
boolean - message:
string - url:
string(url) - type:
object- ext:
string - mime:
string
- ext:
image
Type: Buffer | string
Pass pathname or image content buffers
Author
upimg © metowolf, Released under the MIT License.
