1.0.7 • Published 7 years ago
smms v1.0.7
smms
sm.ms 图床上传插件
安装
npm install smms
使用
// es6
// import uploadImg from 'smms';
// require
const uploadImg = require('smms');
// file 应为 input[type=file] 拿到的 fileList 中的其中一个文件
uploadImg(file).then(data=>{
// todo
});
// 在 jquery 中使用的例子
// html: <input type="file" id="input">
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": "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"
}
}
- 失败示例
{
code: "error",
msg: "No files were uploaded."
}
其他 API
- 上传历史
import {list} from 'smms';
list().then(({code,data})=>{
console.log(data);
})
- 清除历史上传
import {clear} from 'smms';
clear().then(({code,data})=>{
console.log(data);
})
- 删除指定文件
import {remove} from 'smms';
remove(hash).then(({code,data})=>{
console.log(data);
})
详细文档请移步 https://sm.ms/doc/
感谢
感谢 sm.ms 提供的图床服务。
sm.ms 并不是我的站点。
https://github.com/96qbhy/smms
96qbhy@gmail.com