V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
hustlzp
V2EX  ›  Python

如何处理size较大的上传图像?

  •  
  •   hustlzp ·
    hustlzp · 2013-09-03 08:53:06 +08:00 · 2931 次点击
    这是一个创建于 3909 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近在折腾图片上传方面的东西。

    发现Nginx 1.0.5默认的的http body最大为2M,上传超过2M的图片就会报413 Request Entity Too Large。

    当然可以在nginx.conf中加一行:client_max_body_size 5M;

    但其实页面显示不需要这么大的图片,于是再用PIL压缩一下上传图片,然后存盘。

    想请教一下大家是怎么处理这种问题的?
    11 条回复    1970-01-01 08:00:00 +08:00
    9hills
        1
    9hills  
       2013-09-03 08:58:53 +08:00
    1. 上传后处理,可以保留原图和缩略图, 优点是逻辑简单
    2. 上传前处理,比较麻烦,用flash or js来做。。优点是减少传输时间
    koon_kai
        2
    koon_kai  
       2013-09-03 09:06:12 +08:00
    我最近也在弄这个,也是用PIL压缩,关注下看看还有没其他方法。
    twtww
        3
    twtww  
       2013-09-03 10:33:35 +08:00
    tinypic压缩一下吧 http://tinypic.com/
    hustlzp
        4
    hustlzp  
    OP
       2013-09-03 13:57:48 +08:00
    @twtww nice tool!
    hustlzp
        5
    hustlzp  
    OP
       2013-09-03 13:58:41 +08:00
    @9hills 恩,flash就不考虑了。请问你知道有什么这方面的js库吗?
    zenozeng
        6
    zenozeng  
       2013-09-03 14:02:17 +08:00
    如果在前端处理,大概可以减少上传和CPU压力?
    hustlzp
        7
    hustlzp  
    OP
       2013-09-03 14:04:54 +08:00
    @9hills http://stackoverflow.com/questions/5607396/compress-images-on-client-side-before-uploading

    在stackoverflow上找到了相关的资料,看来需要使用canvas了。
    akinoniku
        8
    akinoniku  
       2013-09-03 14:11:57 +08:00   ❤️ 1
    hustlzp
        9
    hustlzp  
    OP
       2013-09-03 14:14:54 +08:00
    @zenozeng 恩,也可以显著减少用户等待时间,减少磁盘占用量。当然也不能压缩得太小,适当压缩,比如4000x3000的压缩成2000x1500的就可以了。
    hustlzp
        10
    hustlzp  
    OP
       2013-09-03 14:15:43 +08:00
    @akinoniku nice!many thanks!
    tioover
        11
    tioover  
       2013-09-03 14:29:01 +08:00
    即使这样也大的话,可以用nginx_upload_module
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   898 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:45 · PVG 05:45 · LAX 14:45 · JFK 17:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.