Name: [1982] Siddhi
Member: 30 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 ...

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

in series: More Django: Intermediate level Django screencasts

video tutorial by Siddhi

(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

Video Tutorials related by tag:

webservice webdevelopment webdev web_development web time showmedos showmedo service server screencasts screencast python programmers programmer process photos photo pages look little library learn home django developers data cover builds build basics basic aws application app amazon

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 2085 (since July 30th)
  • Plays in last week: 12
  • Published: 20 months ago
# 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})

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.

Please provide your email address (won't be published)

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! :)


15. anonymous Wed, 04 Mar 2009 12:10

they changed the way fil upload handeling works in latest django code. If you are having problems, try this:

filename = file.name

content = file.read()

eventually do a read by chunks so not to get slammed by large file:

http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files


14. anonymous Wed, 04 Mar 2009 12:10

they changed the way fil upload handeling works in latest django code. If you are having problems, try this:

filename = file.name

content = file.read()

eventually do a read by chunks so not to get slammed by large file:

http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files


Thanks, your presentation was excellent. Some of you code may now need to be modified now, fyi. If I'm not mistaken, I think newforms has been replaced with the following code (which is the old way):

from django import forms

(instead of, from django import newforms as forms)

see documentation at the following link: http://www.djangoproject.com/documentation/0.96/newforms/

Thanks again!


Very useful and clear!


11. anonymous Sat, 15 Nov 2008 12:10

Thanks a million, It's very clear and easy to follow. I'm trying to learn python + django in order to develop a few small webs and place them in the amazon cloud and I can say that you have helped me greatly (Oh! And python looks great)


10. anonymous Wed, 12 Nov 2008 04:14

Thanks Siddhi, that was exactly what I was looking for! Other examples made it all seem very complicated, now that I've seen the basics I can start adding more layers.

Thanks,

Tyson


9. anonymous Fri, 04 Jul 2008 06:41

They changed the upload handling. in the newest trunk. http://www.djangoproject.com/documentation/upload_handling/

Anyone here, who knows what i have to change ???


8. anonymous Sun, 29 Jun 2008 10:43

Ahhh, sorry my foult, it was my firewall at port 443 !!!


7. anonymous Sun, 29 Jun 2008 07:54

When i test this script, my django dev server hangs-up after a picture post. I use the newest django trunk.


Wow great tutorial, really professional.


Siddhi, your videos are outstanding. Thanks for the great job, your screencasts are inspiring.


Randomly checked ShowMeDo for updates today and saw you added a new Screenscat so I just HAD to watch it :)


Wow that was quick :) Thanks for your comment.


Yet another great screencast Siddhi!

You're doing a great job. I appreciate that.


Video published, thanks for contributing to ShowMeDo


Kudos and Thanks for Siddhi

Learn Python the easy way!
If you want to learn the Python programming language from a very gentle start or are looking to increase your ability to do cool things with Python, check out our club
View this series as a one-page learning-path
This feature is for club members. Click here to find out more.
Your email address will not be published.

Show some quick comments >>








By the Same Author

Siddhi Learn Django shows how easily and quickly you can get a web application up and running wit [...]