Sunday, January 1, 2012

Skip upload of existing S3 Object

I have a model with an ImageField and am using django-storages
S3BotoStorage backend. To reduce load on the server, I'm using
Amazon's S3 Browser Upload functionality[1] to send images directly to
S3. In order to create the model, my plan is have another view take
the uploaded key and save a model instance of my image. Currently my
view code looks something like this:

def add_existing_image(request):
...
image_key = request.POST.get('image_key', None)
im = default_storage.open(image_key)
i = Image(image=im, owner=user)

However, this seems to re-save the image on S3. I was hoping that
since I'm not directly reading the file it would not need to do so
behind the scenes, but it is. Since the goal is to not incur that
overhead, how should I go about creating model instances of these
files that already exist in my storage?

[1] http://aws.amazon.com/articles/1434

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment