npm install smmsbash
npm install smms
`使用
`javascript
// es6
// import uploadImg from 'smms';
// require
const uploadImg = require('smms');
// file 应为 input[type=file] 拿到的 fileList 中的其中一个文件
uploadImg(file).then(data=>{
// todo
});// 在 jquery 中使用的例子
// html:
const input = $('#input');
input.on('change', function (e) {
if(e.target.files.length > 0){
uploadImg(e.target.files[0]).then(data => {
console.log(data);
});
}
});
`返回数据说明
名称
类型
示例值
描述
code
String
success
上传文件状态。正常情况为 success。出现错误时为 error
filename
String
smms.jpg
上传文件时所用的文件名
storename
String
561cc4e3631b1.png
上传后的文件名
size
Int
187851
文件大小
width
Int
1157
图片的宽度
height
Int
680
图片的高度
hash
String
nLbCw63NheaiJp1
随机字符串,用于删除文件
delete
String
https://sm.ms/api/delete/nLbCw63NheaiJp1
删除上传的图片文件专有链接
url
String
https://ooo.0o0.ooo/2015/10/13/561cfc3282a13.png
图片服务器地址
path
String
/2015/10/13/561cfc3282a13.png
图片的相对地址
msg
String
No files were uploaded.
上传图片出错时将会出现
错误列表
Access Denied.
Upload file count limit.
Upload file frequency limit.
Server error. Upload directory isn't writable.
No files were uploaded.
File is empty.
File is too large.
File has an invalid extension.
Could not save uploaded file.
响应示例
1. 成功示例
`
{
"code": "success",
"data": {
width: 1157,
height: 680,
filename: "image_2015-08-26_10-54-48.png",
storename: "56249afa4e48b.png",
size: 69525,
path: "/2015/10/19/56249afa4e48b.png",
hash: "nLbCw63NheaiJp1",
timestamp: 1445239546,
url: "https://ooo.0o0.ooo/2015/10/19/56249afa4e48b.png",
delete: "https://sm.ms/api/delete/nLbCw63NheaiJp1"
}
}
`
2. 失败示例
`
{
code: "error",
msg: "No files were uploaded."
}
`其他 API
1. 上传历史
`javascript
import {list} from 'smms';
list().then(({code,data})=>{
console.log(data);
})
`2. 清除历史上传
`javascript
import {clear} from 'smms';
clear().then(({code,data})=>{
console.log(data);
})
`3. 删除指定文件
`javascript
import {remove} from 'smms';
remove(hash).then(({code,data})=>{
console.log(data);
})
``https://github.com/96qbhy/smms
96qbhy@gmail.com