title: Upload Images to Amazon S3 using Django
body: <p>I'm currently resizing images on the fly when a user uploads a picture. The original picture is stored on Amazon S3 in a bucket called djangobucket. Inside this bucket, contains thousands of folders. </p>
  
  <p>Each folder is named after the user. I don't have to worry about bucket creation or folder creation since all of that is handled from the client side.</p>
  
  <p>Here is a diagram:</p>
  
  <pre><code>djangobucket  ------------&gt; bob ---------&gt; picture1.jpg
                                             picture2.jpg
                                             picture3.jpg
                                             picture4.jpg
  </code></pre>
  
  <p>As you can see, Bob has many pictures. Once a user uploads a picture to S3, I download it through Django via a URL, in this case it would be: <a href="http://s3.amazonaws.com/djangobucket/bob/picture1.jpg" rel="noreferrer">http://s3.amazonaws.com/djangobucket/bob/picture1.jpg</a> </p>
  
  <p>I download the image and perform image processing and save the processed image on my django app server. </p>
  
  <p>I would like to send this processed image back into bob's folder so that it can be publicly reached at <a href="http://s3.amazonaws.com/djangobucket/bob/picture1_processed.jpg" rel="noreferrer">http://s3.amazonaws.com/djangobucket/bob/picture1_processed.jpg</a> </p>
  
  <p>The client already has access to the amazon key and secret key so that he or she can upload pictures to this bucket. All users on the service use the same keys. I too will be using the same keys.</p>
  
  <p>I've heard of something called Boto, but it involves Bucket creation and I'm unsure of how to do just the uploading part. I'm only concerned about uploading the picture to the appropriate user folder. </p>
  
  <p>I've been researching this for hours so I've turned to the experts here.</p>
  
  <p>Here is my code, just so that you can get a better understanding of what I'm doing.</p>
  
  <pre><code>user = 'bob'
  
  url = 'http://s3.amazonaws.com/djangobucket/bob/picture1.jpg'
  filename = url.split('/')[-1].split('.')[0]
  
  download_photo = urllib.urlretrieve(url, "/home/ubuntu/Desktop/Resized_Images/%s.jpg" % (filename))
  downloaded_photo = Image.open("/home/ubuntu/Desktop/Resized_Images/%s.jpg" % (filename))
  
  resized_photo = downloaded_photo.resize((300, 300), Image.ANTIALIAS)
  new_filename = filename + "_processed"
  
  resized_photo.save("/home/ubuntu/Desktop/Resized_Images/%s.jpg" % (new_filename)) 
  </code></pre>
  
  <p>I would like to send the resized photo saved in /home/ubuntu/Desktop/Resized_Images/
  to Bob's folder in the djangobucket on Amazon S3 and make it publicly visible.</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>EDIT</strong>
  I found this link: <a href="http://www.laurentluce.com/posts/upload-and-download-files-tofrom-amazon-s3-using-pythondjango/" rel="noreferrer">http://www.laurentluce.com/posts/upload-and-download-files-tofrom-amazon-s3-using-pythondjango/</a></p>
  
  <p>Not quite how to use it for my case, but I think I'm on the right track.</p>