python使用token验证,通过api上传图片到图床 EasyImages2.0
2023-09-27 14:22:22 时间
简介:
最近又开始做odoo了,发现odoo将照片全存在数据库里面,使用base64编码,这可就不方便了。
导入数据的时候不能导入。
不过odoo也有一个显示url图片的功能。
那么就要考虑将图片存在图床了。
总不能让用户手动上传再填url地址吧?
就找了个支持api上传带token验证的图床:EasyImages2.0
https://github.com/icret/EasyImages2.0
还挺好用的。
也有docker版本:
由热心TG网友Derek DDS
制作的docker版本
https://github.com/DDSRem/easyimage
https://hub.docker.com/r/ddsderek/easyimage
就用它吧。
一:docker安装
略
二:安装后打开api
设置--图床安全--API上传 打开即可
三:token设置
设置--api设置--Token列表 注意检查一下token有效期,不行就新建几个
四:python测试API上传
源码如下
import requests def sendImg(img_name, img_type="image/jpeg"): f_abs = open(img_name, "rb") url = "http://192.168.1.221:8081/api/index.php" # 自己想要请求的接口地址 proxies = { #网络嗅探用代理,可以取消 "http": "http://127.0.0.1:12888", } body = { "image": (img_name, f_abs, img_type) } data = { "token": "02559eb5cc28720d502eff1758ffd8d2" } response = requests.post(url=url, files=body, data=data, proxies=proxies) return response if __name__ == "__main__": # 上传图片 img_name = "2.jpg" res = sendImg(img_name) # 调用sendImg方法 print(res.json())
相关文章
- Python的re模块的match和fullmatch方法的区别
- Word处理控件Aspose.Words功能演示:在 Python 中将 HTML 转换为 PNG、JPEG、BMP、GIF 或 TIFF 图像
- 用python画 pareto front
- Google Earth Engine Python ——使用sentinel-1数据识别火灾前后的结果
- python中moviepy库的用法详解
- 精心整理的8道Python经典面试题合集!
- 如何用Python批量发现互联网“开放”摄像头
- 使用 Python 创建你自己的 Shell(下)
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 【Python】时间转换(可用于计算耗时场景)
- 【Python】+Django+Vue+Element UI 实现图片上传功能
- 【Python】【PyPI】twine模块打包python项目上传pypi
- 【Python】自动化测试请求文件上传接口
- python 列表list相关操作
- Python基础图形绘制库——turtle
- 基于python实现的(窗体)家族信息管理系统【100010690】
- Python高级架构模式的整理
- And one thing may differ I found is that, it only compatible with python3,so when your default pip installed in python is 2.7 not python3 you need use "python3 -m pip install chefboost" instead
- Python heapq实现大顶堆
- Python与Django项目开发,使用inspect、signature、装饰器进行参数检查,QuerySet转List、Dict,以及数据操作方法的二次封装,解决业务和数据存储之间的耦合