Is it possible to find a file in filer with his number?

75 views
Skip to first unread message

Asakusa Tokugawa

unread,
Jun 22, 2013, 6:50:02 PM6/22/13
to django...@googlegroups.com
Hi,

I used the filer for more than a week and it works fine. But now, I have two problems.

1) 
Is it possible to find a file in filer with his number (e.g. 162, when the admin path is "/en/admin/filer/image/162/").
My problem is that I want to find the location (optimally the url for this file) by using the number.
The reason for this is that I want to provide images for download and they should not be opened directly in the browser but rather the save-dialog should 
appear. Does anyone have a code snippet for this problem or another idea?

2)
The other problem with the filer is in combination with the "easy thumbnails".
When I try 

thumb = get_thumbnailer('/media/filer_public/2013/06/11/399301_10151170147233531_2039543998_n_1.jpg')

I get the following error:
SuspiciousOperation at /en/admin/filer/image/162/getImage
Attempted access to '/media/filer_public/2013/06/11/399301_10151170147233531_2039543998_n_1.jpg' denied.

Info: The getImage method is in the views.py
When I use it with the hostname, I receive (e.g.: http://localhost:8000/media/filer...) that error:

InvalidImageFormatError at /en/admin/filer/image/162/getImage
The source file does not appear to be an image

Is the URL entered in the browser, the image is displayed.

But when I use the direct path (e.g. /var/www/mydjangoproject/....) it works perfect.
However, when I get the URL with "thumb.url", I get the path (which I had entered) instead the
URL (like http://localhost...) .
Does anyone has a hint for me?

Thx,
Asakusa

Stefan Foulis

unread,
Jun 24, 2013, 3:03:23 AM6/24/13
to django...@googlegroups.com
Hi Asakusa

You can get a specific File by id by getting it from the Database:

from filer.models import File
f = File.objects.get(id=42)
print f.url


I think get_thumbnailer assumes you are using a absolute path in your filesystem if the string starts with '/'. If you are using the default storage backend in filer, it might work if you provide the path relative to the root of the used storage backend ('filer_public/2013/06/11/399301_10151170147233531_2039543998_n_1.jpg').
django-filer file models behave like a regular file field when used with easy-thumbnails. So this should also work and will use the correct storage backends:
thumb = get_thumbnailer(File.objects.get(id=42))

Cheers
Stefan

Asakusa Tokugawa

unread,
Jun 24, 2013, 2:44:14 PM6/24/13
to django...@googlegroups.com
Hi Stefan,

thank you very much for your quick feedback. I was able to solve both problems with "File.objects.get(id=42)".
Great forum, thx!

Regards,
Asakusa
Reply all
Reply to author
Forward
0 new messages