smms

1.0.7 • Public • Published

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 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"
    }
}
  1. 失败示例
{
    code: "error",
    msg: "No files were uploaded."
}

其他 API

  1. 上传历史
import {list} from 'smms';
list().then(({code,data})=>{
    console.log(data);    
})
  1. 清除历史上传
import {clear} from 'smms';
clear().then(({code,data})=>{
    console.log(data);    
})
  1. 删除指定文件
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

Readme

Keywords

Package Sidebar

Install

npm i smms

Weekly Downloads

4

Version

1.0.7

License

MIT

Last publish

Collaborators

  • 96qbhy