推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
honmaple
V2EX  ›  Python

用 Python 写了一个简单的图片上传存储服务

  •  
  •   honmaple · Mar 14, 2017 · 2442 views
    This topic created in 3373 days ago, the information mentioned may be changed or developed.

    七牛什么的自定义域名竟然还需要备案,所以花两天时间写了一个简单的图片上传存储服务(基于 flask)

    示例,使用 requests上传图片

    import requests
    
    def images():
        url = 'http://127.0.0.1:8000/api/images'
        files = {'images': open('desktop.png', 'rb')}
        multiple_files = [
            ('images', ('11.png', open('11.png', 'rb'), 'image/png')),
            ('images', ('desktop.png', open('desktop.png', 'rb'), 'image/png'))
        ]
        headers = {
            'Api-Key':
            'InhpeWFuZzA4MDdJBtx4AWlPpI_Oxx1Ki8',
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'
        }
        # r = requests.post(url, files=multiple_files, headers=headers)
        r = requests.post(url, files=files, headers=headers)
        print(r.text)
    

    GitHub 地址: https://github.com/honmaple/maple-file

    6 replies    2017-03-16 15:10:41 +08:00
    ipconfiger
        1
    ipconfiger  
       Mar 14, 2017
    支持自动多尺寸 thumbnail 不?
    honmaple
        2
    honmaple  
    OP
       Mar 14, 2017
    @ipconfiger 目前只是保存原图及生成 width=300 的缩略图,后续可能会加上
    honmaple
        3
    honmaple  
    OP
       Mar 14, 2017
    @ipconfiger 现在可以使用 url/40965530537.png?width=300&height=100,不过只支持等比缩放
    felinx
        4
    felinx  
       Mar 14, 2017   ❤️ 1
    @ipconfiger 自己架一个图片处理的服务也容易,有开源的一些解决方案可参考,稍作改动可以达到类似于七牛自定义后缀规则的效果 https://github.com/agschwender/pilbox
    kba977
        5
    kba977  
       Mar 15, 2017
    七牛不是有 api 么 直接上传不就好了~~~
    honmaple
        6
    honmaple  
    OP
       Mar 16, 2017
    @kba977 是因为自定义域名要备案才自己写的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5398 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 07:35 · PVG 15:35 · LAX 00:35 · JFK 03:35
    ♥ Do have faith in what you're doing.