Name: [1982] Siddhi
Member: 88 months
Authored: 4 videos
Description: I'm an entrepreneur from Chennai, India and I have my own company `Silver Stripe Software <http://www.silverstripesoftware.com>`_ where I develop tools for agile software development using Python and Django. My passion is in the startup ecosystem (especially in India), agile development and manageme ...

Using Amazon's S3 service with Django [ID:717] (1/1)

in series: More Django: Intermediate level Django screencasts

video tutorial by Siddhi, added 05/08

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

Amazon's S3 service has been a hit with developers who need to store and serve large amounts of data in a scalable way. In this screencast we'll see how we can use S3 in a Django application.

We'll build a simple gallery app, but instead of storing the photos locally, we'll store them on S3 and then serve the photos directly from the S3 server. In the process, we'll learn the basics of using the boto library to interact with Amazon Web Services.

This screencast assumes you know the basics of Django. If you are new to Django, take a look at the Learn Django series on showmedo.

Links

boto: python library for Amazon web services Amazon S3 home page

# Create your views here.
import mimetypes
from django.shortcuts import render_to_response
from django import newforms as forms
from django.conf import settings
from boto.s3.connection import S3Connection
from boto.s3.key import Key

from models import PhotoUrl

class UploadForm(forms.Form):
    file = forms.ImageField(label='Select photo to upload')

def index(request):
    def store_in_s3(filename, content):
        conn = S3Connection(settings.ACCESS_KEY, settings.PASS_KEY)
        b = conn.create_bucket("siddhartafiles")
        mime = mimetypes.guess_type(filename)[0]
        k = Key(b)
        k.key = filename
        k.set_metadata("Content-Type", mime)
        k.set_contents_from_string(content)
        k.set_acl("public-read")
        
    photos = PhotoUrl.objects.all().order_by("-uploaded")
    if not request.method == "POST":
        f = UploadForm()
        return render_to_response("index.html", {"form":f, "photos":photos})

    f = UploadForm(request.POST, request.FILES)
    if not f.is_valid():
        return render_to_response("index.html", {"form":f, "photos":photos})

    file = request.FILES["file"]
    filename = file["filename"]
    content = file["content"]
    store_in_s3(filename, content)
    p = PhotoUrl(url="http://siddhartafiles.s3.amazonaws.com/" + filename)
    p.save()
    photos = PhotoUrl.objects.all().order_by("-uploaded")
    return render_to_response("index.html", {"form":f, "photos":photos})

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 5608 (since July 30th)
  • Plays in last week: 2
  • Published: 79 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>








All comments excluding tick-boxed quick-comments

That was a wonderful tutorial! You made my day. I hope you make more s3 videos.


44. David Goldberg Fri, 07 May 2010 18:39

Genius! Been looking for somewhere to explain how to integrate Amazon S3 and Django this was perfect.


Thank you! It's what I just needed :)


Gr8 tutorial Sid!

Please upload some more when you get some time!

Thanks


41. Valeriu Palos Mon, 29 Mar 2010 22:12

Very useful screencasts, thank you very much! I'm new to python and hooked on your tutorials. I will try posting them on my blog as well. Hope to see more of them.


Great demo. Very thorough giving a full picture. Would be nice to do a review at the end of the most critical elements.


Good enough to understand django/s3 usage together.


37. anonymous Sat, 02 Jan 2010 13:59

very nice tutorial. keep up the good work.


36. anonymous Mon, 28 Dec 2009 06:30

Nice Tutorial


35. anonymous Mon, 21 Dec 2009 10:55

Thanks for showing how easy it is to use boto with s3.


34. anonymous Sun, 13 Dec 2009 21:27

Very informative! Thanks for taking the time to do this video.


33. anonymous Fri, 04 Dec 2009 17:42

You don't want to transfer the upload contents to your server then to S3. you should instead have the user's browser directly upload to S3.

See:

http://developer.amazonwebservices.com/connect/entry!default.jspa?categoryID=139&externalID=1434&fromSearchPage=true


32. anonymous Fri, 27 Nov 2009 14:32

Thanks so much for this! Very easy to follow!


31. anonymous Tue, 24 Nov 2009 01:33

Do you know how to embed amazon store to our website?


30. anonymous Tue, 10 Nov 2009 16:55

Interesting video. I'm trying to understand the uses of Django with hosting and clouds.


Thanks Siddhi. Great job as always. How about some more intermediate Django vids?


28. anonymous Thu, 22 Oct 2009 01:07

Thunderbird 3: I love Firefox but it loads pages slowly. ,


27. anonymous Tue, 13 Oct 2009 01:00

What is the social philosophy of the document? ,


26. anonymous Mon, 05 Oct 2009 10:42

Great information! Thanks for your work!


25. anonymous Thu, 03 Sep 2009 21:09

that was awesome dude...keep it up, I'm new to django and I'm learning a lot thanks dude


24. anonymous Wed, 26 Aug 2009 13:41

Big thanks, it helps me alot :)


23. anonymous Fri, 14 Aug 2009 03:07

Hey Sid, That was an excellent intro to s3. I have bookmarked your screen cast for future reference. I really hope you find time to upload more AWS screen casts. Maybe something about hosting the Django app on EC2?

Once again, thank you!

Best,

Saravana


Thanks for all the comments. For anyone viewing this video, please keep in mind the changes you need to do for the latest Django version. You can find the changes in the comments.

@anonymous You can find out more about authentication in S3 here - http://docs.amazonwebservices.com/AmazonS3/latest/UsingAuthAccess.html


21. anonymous Mon, 20 Jul 2009 14:51

Hi Siddhi,

Awesomee...this is going to be of great help. I am trying to make an application which is running on Django and stores images on S3. ..almost the same thing which u did in your video. Only thing i want to know/figure out is how to add users on my website...i.e. All users can upload thier images in a one big bucket and user A can not access user Bs data. Any idea...suggestions..?


20. anonymous Fri, 26 Jun 2009 15:21

Fantastic your video about S3,

Its not for me now, but maybe in future.

Thank very much Siddhi

Santi from Spain

I am a fan of you


19. anonymous Thu, 18 Jun 2009 20:26

Nice Tutorial thx for everything


18. anonymous Thu, 28 May 2009 09:03

Great! Would love to see a part2 where you integrate the use of SimpleDB to this app.


17. anonymous Sun, 22 Mar 2009 14:09

Thanks Siddhi for your Django tutorials.

I've just finished the Django official tutorial and this is an excelent "desert".


16. anonymous Sat, 21 Mar 2009 15:57

Hey great video, I came here looking for s3 manipulation technicques but ended up watching it anyways cuz I like django too! thanks for sharing! :)


Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Siddhi

Content

Feedback

Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.

feedback@showmedo.com