问题
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!
回答1:
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.
回答2:
You were close. But the library required was different.
The answer, helped me, is here https://stackoverflow.com/a/23445746/1478569
来源:https://stackoverflow.com/questions/9271267/uploading-a-jpeg-image-via-django-displays-error