上传API

自ImgURL Pro v1.1开始,支持token参数,token需要在后台生成(当传递token参数上传数量不受限制),如下图。

img

上传接口

请求参数

参数名 类型 是否必须 参数说明
file file 支持jpg/jgeg/png/gif/bmp/webp格式
token string 如果传递token则视为管理员上传

返回值

如果请求成功,返回结果如下

{
	"code": 200,
	"id": 35,
	"imgid": "ead2649f723a346c",
	"relative_path": "/imgs/2019/10/ead2649f723a346c.png",
	"url": "http://pro.imgurl.org/imgs/2019/10/ead2649f723a346c.png",
	"thumbnail_url": "http://pro.imgurl.org/imgs/2019/10/ead2649f723a346c_thumb.png",
	"width": 1381,
	"height": 645,
	"delete": "http://pro.imgurl.org/delete/849a3ae44d87b641"
}
参数名 类型 参数说明
code int 状态码,200:成功,0:失败
id int id(唯一)
imgid string 图片id(唯一)
relative_path string 图片相对路径
url string 图片URL
thumbnail_url string 缩略图URL
width int 图片宽
height int 图片高
delete string 图片删除链接,若此图片之前已上传过,返回空

如果失败,返回结果为

{"code":0,"msg":"The filetype you are attempting to upload is not allowed."}

演示代码

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>ImgURL上传测试</title>
    <meta name="generator" content="EverEdit" />
    <meta name="author" content="" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
</head>
<body>
    <form enctype="multipart/form-data" method="post" action="http://test.imgurl.org/api/upload" id="upform">
    <input type="file" name="file" class="up-file">
    <input type="submit" id="btn" value="开始上传" class="btn">
    </form>
</body>
</html>

探索发现

探索发现返回游客最新上传的图片,不显示管理员图片和可疑图片,说明如下。

返回的结果如下:

[{
	"id": "15",
	"imgid": "9fde71fb50e4efe3",
	"path": "\/imgs\/2019\/04\/9fde71fb50e4efe3.png",
	"thumb_path": "\/imgs\/2019\/04\/9fde71fb50e4efe3_thumb.png",
	"date": "2019-04-10 16:41",
	"compression": "0",
	"level": "unknown",
	"mime": "image\/png",
	"width": "720",
	"height": "400",
	"views": "1",
	"ext": ".png",
	"client_name": "yz.png"
}, {
	"id": "14",
	"imgid": "e28dc32685726892",
	"path": "\/imgs\/2019\/04\/e28dc32685726892.png",
	"thumb_path": "\/imgs\/2019\/04\/e28dc32685726892_thumb.png",
	"date": "2019-04-10 16:37",
	"compression": "0",
	"level": "unknown",
	"mime": "image\/png",
	"width": "816",
	"height": "373",
	"views": "0",
	"ext": ".png",
	"client_name": "snipaste_20180908_164604.png"
}]

返回参数说明

其它参数

除了默认返回游客最新的16张图片外,还支持对图片进行筛选,比如gif动态图片,只需要在/api/found追加参数即可。


Revision #1
Created 11 August 2021 04:24:54 by xiaoz
Updated 11 August 2021 04:26:40 by xiaoz