Loading JPEG image via Django displays error

I am running a Django application in virtualenv on Ubuntu using NGINX / FastCGI and am trying to load a JPG image into a Django admin application.

I get this error: "Upload a valid image. The file you uploaded was either not an image or a damaged image." I can upload a GIF image, so this only calls JPEG.

Here is what I have 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 installation, 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 is supported. I also checked the check manually and confirmed:

 >>> 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 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 your luck with the pillow (PIL plug)

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

I am running Django. I am also trying to stop and start the nginx service after each PIL installation.

So far, none of the above approaches have passed me the previous error message in my Django application on Ubuntu. I can upload the same JPG image, just fine in my local dev block (Mac OSX 10.6.5) running the same Django application, so I know something with my deployment on Ubuntu.

Any help would be appreciated!

+2
source share
2 answers

Good thing you know, I decided to quit the Django admin and log in ... all of a sudden everything works fine! Sheesh. The last thing I tried was approach number 2 above, so if anyone has this problem, this is the best solution.

+1
source

You were close. But the library was different.

The answer helped me here fooobar.com/questions/921521 / ...

0
source

Source: https://habr.com/ru/post/921512/


All Articles