简单图像上传程序
imgtohttps的Python项目详细描述
关于
通过url将所有不安全的图像上载到imgur的微服务。
使用redis作为缓存后端和元数据存储。
安装
安装uwsgi和python3插件:
sudo apt-get install uwsgi uwsgi-plugin-python3
制作virtualenv:
cd /opt pyvenv-3.4 img_service source img_service/bin/activate
从pypi安装:
pip install imgtohttps
为应用程序创建配置文件:
[uwsgi] plugins = python34 master = true enable-threads = true processes = 4 module = imgtohttps.application:app virtualenv = /opt/img_service chdir = /opt/img_service touch-reload = /opt/img_service/reload env=APP_SETTINGS=settings.Production
连接到nginx:
server { listen 127.0.0.1:2100; access_log off; location / { uwsgi_pass unix:/run/uwsgi/app/img_service/socket; include uwsgi_params; } }
用法
请求:
curl -X POST -H "Content-Type: application/json" -d '{"url": "http://example.com/image.png"}' http://localhost:2100
响应:
{"url": "https://i.imgur.com/AxQwu0h.png"}
错误:
{"error": "Some error message"}