django-imagefit icon indicating copy to clipboard operation
django-imagefit copied to clipboard

Doesn't support S3 Image backend right?

Open manuganji opened this issue 7 years ago • 5 comments

Hi, I'm trying to use your package with django-s3direct and it is raising a file error.

Internal Server Error: /imagefit/resize/150x150,C/https://s3.amazonaws.com/wRCTXuPgbEOtbTzhRI8Ht.png Traceback (most recent call last): File "/home/manu/.virtualenvs/project/lib/python3.5/site-packages/django/core/handlers/exception. py", line 35, in inner response = get_response(request) File "/home/manu/.virtualenvs/project/lib/python3.5/site-packages/django/core/handlers/base.py", line 128, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/manu/.virtualenvs/project/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/manu/.virtualenvs/project/lib/python3.5/site-packages/imagefit/views.py", line 40, in resize image = Image(path=os.path.join(prefix, url)) File "/home/manu/.virtualenvs/project/lib/python3.5/site-packages/imagefit/models.py", line 21, in init self.pil = PilImage.open(path) File "/home/manu/.virtualenvs/project/lib/python3.5/site-packages/PIL/Image.py", line 2548, in open fp = builtins.open(filename, "rb") FileNotFoundError: [Errno 2] No such file or directory: 'https://s3.amazonaws.com/ wRCTXuPgbEOtbTzhRI8Ht.png'

manuganji avatar May 01 '18 23:05 manuganji

The image at https://s3.amazonaws.com/wRCTXuPgbEOtbTzhRI8Ht.png does not exist or is not publicly available; it even returns an XML! I suppose that's why you have a FileNotFoundError. (We should raise a 404 instead though).

You may want to try with an existing image hosted on AWS S3 and see if that works for yourself. (eg: http://resource.download.wjec.co.uk.s3.amazonaws.com/vtc/2014-15/Int_Media/unit2/images/logo_iceland.png)

vinyll avatar May 02 '18 09:05 vinyll

Hi @vinyll thanks for your reply. I purposely edited the file url to not reveal the link. Is this package tested to work remotely hosted images?

manuganji avatar May 02 '18 11:05 manuganji

It is supposed to work with full url images. Therefore there’s nothing like a notion of backend for aws s3 here, just reading content from a remote url.

If that was not the case you’re facing bug that shouldn’t be specific to aws. Could you test with some other random remote image that is not on Amazon? My laptop died a couple of days ago and it makes it tricky for me to test these things. Thanks 👌

vinyll avatar May 02 '18 23:05 vinyll

Hey! I've faced the same problem. My site images are stored on remote servers. I did not set IMAGEFIT_ROOT setting at all and trying to render images. There I have an "FileNotFoundError: [Errno 2] No such file or directory: 'https://my_remote_url/file_name.jpg'" error whatever url I take. On my template the full path to the image is "/image/resize/thumbnail/https://my_remote_url/file_name.jpg". This is very helpful and nice app, but can it really get images from remote?

BrealX avatar Jun 11 '18 07:06 BrealX

Mhhh… I guess some debugging session would be necessary for that one. I assume we should explicitely have something like a url_resize() template tag (see the media or static resize helpers) that would probably copy the file from the url and save it as a temporary file.

I won't have enough of time to implement this in the very next days, though it looks fun to do. If any good soul is willing to go for a PR, I will be cooperative and can try to be responsive ;)

vinyll avatar Jun 13 '18 21:06 vinyll