继上次发现Chevereto提供一个上传的api后,一直想在我的图床做点好玩的事。

在写这篇文章之前已经上传了很多wlop的插画,我图床用着阿里云的OSS当外部存储,8K原图一张几十兆,服务器往OSS传的太慢还买了一天提升带宽勉强够用...

_20200618173155.png

进入正题。

准备工作

看了api文档,上传本地文件基本只能使用post方式,用get要把图片转base64编码,图片大了很容易超出最大url长度。

api-doc.png

可选参数:

Parameters description
key The API v1 key, it can be set in your admin dashboard settings.
action What you want to do values: upload.
source Either a image URL or a base64 encoded image string. You can also use FILES "source" in your request.
format Sets the return format values: json (default), redirect, txt.

我们先在postman里测试一下:(因为现在备案还没过,先用的临时域名,所以图中打码)

postman

返回200,没问题,我们来看一下返回的json内容格式:


{
        "status_code": 200,
        "success": {
            "message": "image uploaded",
            "code": 200
        },
        "image": {
            "name": "example",
            "extension": "png",
            "size": 53237,
            "width": 1151,
            "height": 898,
            "date": "2014-06-04 15:32:33",
            "date_gmt": "2014-06-04 19:32:33",
            "storage_id": null,
            "description": null,
            "nsfw": "0",
            "md5": "c684350d722c956c362ab70299735830",
            "storage": "datefolder",
            "original_filename": "example.png",
            "original_exifdata": null,
            "views": "0",
            "id_encoded": "L",
            "filename": "example.png",
            "ratio": 1.2817371937639,
            "size_formatted": "52 KB",
            "mime": "image/png",
            "bits": 8,
            "channels": null,
            "url": "http://127.0.0.1/images/2014/06/04/example.png",
            "url_viewer": "http://127.0.0.1/image/L",
            "thumb": {
                "filename": "example.th.png",
                "name": "example.th",
                "width": 160,
                "height": 160,
                "ratio": 1,
                "size": 17848,
                "size_formatted": "17.4 KB",
                "mime": "image/png",
                "extension": "png",
                "bits": 8,
                "channels": null,
                "url": "http://127.0.0.1/images/2014/06/04/example.th.png"
            },
            "medium": {
                "filename": "example.md.png",
                "name": "example.md",
                "width": 500,
                "height": 390,
                "ratio": 1.2820512820513,
                "size": 104448,
                "size_formatted": "102 KB",
                "mime": "image/png",
                "extension": "png",
                "bits": 8,
                "channels": null,
                "url": "http://127.0.0.1/images/2014/06/04/example.md.png"
            },
            "views_label": "views",
            "display_url": "http://127.0.0.1/images/2014/06/04/example.md.png",
            "how_long_ago": "moments ago"
        },
        "status_txt": "OK"
    }

一应俱全。

之后就有大概思路了:

  • 爬取图片保存本地
  • 遍历本地图片上传后台

数据爬取部分(此爬虫仅供学习使用,不得用于商业用户,侵删

此处内容需要评论回复后(审核通过)方可阅读。

本地上传部分

此处内容需要评论回复后(审核通过)方可阅读。

最后修改:2020 年 07 月 23 日 05 : 23 PM
如果觉得我的文章对你有用,请随意赞赏