通过Django上传JPEG图像显示错误 [英] Uploading a JPEG image via Django displays error

查看:528
本文介绍了通过Django上传JPEG图像显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NGINX / FastCGI在Ubuntu的virtualenv中运行Django应用程序,并尝试将JPG图像上传到Django管理员应用程序。



我是得到此错误:上传有效的图像。您上传的文件不是图像或损坏的图像。我可以上传一个GIF图像,所以只有JPEG是造成问题的。



这是我迄今为止所尝试的:



1)在PIL之前安装libjpeg62-dev

  pip卸载pil 
sudo apt-get libjpeg62- dev
pip安装pil

在PIL安装结束时,我看到: p>

  PIL 1.1.7设置汇总
------------------ --------------------------------------------------
版本1.1.7
平台linux2 2.6.5(r265:79063,2010年4月16日,13:09:56)
[GCC 4.4.3]
---- -------------------------------------------------- --------------
*** TKINTER支持不可用
--- JPEG支持可用
--- ZLIB(PNG / ZIP)支持可用
--- FREETYPE2支持可用
*** LITTLECMS支持不可用

所以看起来像是JPEG支持。我也进行了手动测试以验证并验证:

 >>>来自PIL import Image 
>>> trial_image = Image.open(/ path / to / my / image.png)
>>> try_image.verify()

2)与上述方法#1相似,但手动指定JPG_ROOT: / p>

  pip卸载pil 
sudo apt-get libjpeg62-dev
pip install --no-install pil
vi /path/to/virtualenv/build/PIL/setup.py(JPG_ROOT = libinclude(/ usr / lib))
pip install pil
/ pre>

3)尝试我的运气与枕头(一个PIL叉)

  pip卸载pil 
sudo apt-get libjpeg62-dev
点安装枕头



我正在运行Django,我也试着停止&在每次安装PIL后启动nginx服务。



到目前为止,上述方法都没有让我超越我在Ubuntu中的Django应用程序中的上述错误消息。我可以在我的本地开发框(Mac OSX 10.6.5)上上传相同的JPG图像,运行相同的Django应用程序,所以我知道这是我在Ubuntu上的部署。



任何帮助将不胜感激!

解决方案

你知道什么,我决定退出Django管理员重新登录....突然它工作正常!啧。我尝试的最后一件事是上面的#2,所以如果有人遇到这个问题,那是你最好的解决方案。


I'm running a Django app inside a virtualenv on Ubuntu with NGINX/FastCGI and trying to upload a JPG image to the Django admin app.

I'm getting this error: "Upload a valid image. The file you uploaded was either not an image or a corrupted image." I can upload a GIF image, so it's only JPEG that's causing the problem.

Here's what I've tried so far:

1) Install libjpeg62-dev before PIL

pip uninstall pil
sudo apt-get libjpeg62-dev
pip install pil

At the end of the PIL install, I see:

PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
              [GCC 4.4.3]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available

So it looks like JPEG support is there. I've also done the manual test to verify and it verified:

>>> from PIL import Image
>>> trial_image=Image.open("/path/to/my/image.png")
>>> trial_image.verify()

2) Similar to approach #1 above, but manually specifying the JPG_ROOT:

pip uninstall pil
sudo apt-get libjpeg62-dev
pip install --no-install pil
vi /path/to/virtualenv/build/PIL/setup.py (JPG_ROOT = libinclude("/usr/lib"))
pip install pil

3) Try my luck with Pillow (a PIL fork)

pip uninstall pil
sudo apt-get libjpeg62-dev
pip install pillow    

I'm running Django under I've also trying stopping & starting the nginx service after each time installing PIL.

So far none of the above approaches have gotten me past the above error message in my Django app on Ubuntu. I can upload the same JPG image just fine on my local dev box (Mac OSX 10.6.5) running the same Django app, so I know it's something with my deployment on Ubuntu.

Any help would be appreciated!

解决方案

Well what do you know, I decided to log out of the Django admin and log back in....suddenly it works fine! Sheesh. The last thing I tried was approach #2 above so if anyone is having this problem, that's your best solution.

这篇关于通过Django上传JPEG图像显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆