开发者

In Django, how to get django-storages, boto and easy_thumbnail to work nicely?

I'm making a website where files are uploaded through the admin and this will then store them on Amazon S3. I'm using django-storages and boto for this, and it seems to be working just fine.

Thing is, I'm used to use my easy_thumbnails (the new sorl.thumbnai开发者_如何学Cl) on the template side to create thumbnails on the fly. I prefer this approach, rather than the model side, as it allows for easier maintenance if ever I decide to change the thumbnail size at a later date etc.

But I'm realising that easy_thumbnails doesn't seem to like reading the image now it's stored on Amazon S3. Also, I realised, where exactly would it be putting the thumbnails once made anyhow? Obviously, I'd prefer these to be on Amazon S3 as well. But how do I get these two technologies to play nice?

How would I get easy_thumbnails to store the thumb it creates back on Amazon S3? Or am I just looking at this all wrong?!

Thanks!


easy_thumbnails will do S3-based image thumbnailing for you - you just need to set settings.THUMBNAIL_DEFAULT_STORAGE, so that easy_thumbnails knows which storage to use (in your case, you probably want to set it to the same storage you're using for your ImageFields).


I changed how I use it...

I modified my model to have a field for the thumbnail:

class Photo(models.Model)
    image = models.ImageField(upload_to=image_upload_to)
    thumb_a = ThumbnailerImageField(upload_to=thumb_a_upload_to, resize_source=dict(size=(98,98), crop='center'),)

and on the template, instead of:

{% load thumbnail %}
<img src="{% thumbnail photo.image 98x98 crop='center' %}">

I changed it to...

<img src="{{photo.thumb_b.url}}">

When I upload the photo I now do...

for i in listOfImages:
    form = CreatePhotoForm(request.POST, i)
        if form.is_valid():
            asdf = form.save(commit=False)
            asdf.owner = request.user
            asdf.image = i
            asdf.thumb_a = i
            asdf.title = str(i)
            asdf.save()

It works pretty well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜