Skip upload of existing S3 Object

229 views
Skip to first unread message

Chris Hasenpflug

unread,
Jan 1, 2012, 6:25:07 AM1/1/12
to Django users
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

Ivo Brodien

unread,
Jan 1, 2012, 4:45:38 PM1/1/12
to django...@googlegroups.com
Hi,

the form sends the picture to S3 and then S3 calls you on an URL which you specify with “ success_action_redirect”. This should point to an URL on your server where you then store the key/hash which will be provided in the URL.

Your code uses POST data but S3 will put the metadata in the URL (=GET) (bucketkey and etag)

So just make sure that your forms posts to S3 and you define the success_action_redirect URL.

I think you actually don’t need the S3StorageBackend since you are not storing anything or at least it does not actually pass your server.

hope that helps!

Cheers
Ivo


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


Chris Hasenpflug

unread,
Jan 5, 2012, 11:11:15 PM1/5/12
to Django users
The reason I'm POSTing after the direct upload to S3 I need to create
the model with extra data. As far as I can tell S3's
success_action_redirect doesn't allow you to pass additional
information.

Additionally, since this is an ImageField, I can't set the key
directly. At the moment, I've resorted to Raw SQL :( What have I
missed?

Rise Riyo

unread,
Mar 17, 2014, 11:10:33 PM3/17/14
to django...@googlegroups.com
Hi, Chris, 

Were you able to get this working? I'm in the same situation. 


I don't want to resend my files (user computer -> Heroku -> S3) since I already have them on S3. I have django-storages set up because I need to generate thumbnails, and I need access to S3 to upload videos from S3 (to Heroku) to Vimeo. 

So my question is 1) do I not submit the uploaded files by not placing them within the <form> html tags, 2) do I submit the files to Heroku but not do anything to these files? 3) Do I take the full URL path of my files stored on S3 and save that full url path as a string to my FileField and ImageField attributes in my model?

Please let me know. Thanks well in advance. - Rise

palansh agarwal

unread,
Nov 27, 2017, 5:03:30 AM11/27/17
to Django users
Hi Chris,
Were you able to solve this? I am in a similar situation.
Reply all
Reply to author
Forward
0 new messages