Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:44:27+00:00 2026-05-29T19:44:27+00:00

I am trying to implement a function in Django to upload an image from

  • 0

I am trying to implement a function in Django to upload an image from a client (an iPhone app) to an Amazon S3 server. The iPhone app sends a HttpRequest (method PUT) with the content of the image in the HTTPBody. For instance, the client PUTs the image to the following URL: http://127.0.0.1:8000/uploadimage/sampleImage.png/

My function in Django looks like this to handle such a PUT request and save the file to S3:

def store_in_s3(filename, content):
    conn = S3Connection(settings.ACCESS_KEY, settings.PASS_KEY) # gets access key and pass key from settings.py
    bucket = conn.create_bucket("somepicturebucket")
    k = Key(bucket)
    k.key = filename
    mime = mimetypes.guess_type(filename)[0]
    k.set_metadata("Content-Type", mime)
    k.set_contents_from_string(content)
    k.set_acl("public-read")

def upload_raw_data(request, name):
    if request.method == 'PUT':
        store_in_s3(name,request.raw_post_data)
        return HttpResponse('Upload of raw data to S3 successful')
    else:
        return HttpResponse('Upload not successful')

My problem is how to tell my function the name of the image. In my urls.py I have the following but it won’t work:

url(r'^uploadrawdata/(\d+)/', upload_raw_data ),

Now as far as I’m aware, d+ stands for digits, so it’s obviously of no use here when I pass the name of a file. However, I was wondering if this is the correct way in the first place. I read this post here and it suggests the following line of code which I don’t understand at all:

file_name = path.split("/")[-1:][0]

Also, I have no clue what the rest of the code is all about. I’m a bit new to all of this, so any suggestions of how to simply upload an image would be very welcome. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:44:34+00:00Added an answer on May 29, 2026 at 7:44 pm

    This question is not really about uploading, and the linked answer is irrelevant. If you want to accept a string rather than digits in the URL, in order to pass a filename, you can just use w instead of d in the regex.

    Edit to clarify Sorry, didn’t realise you were trying to pass a whole file+extension. You probably want this:

    r'^uploadrawdata/(.+)/$'
    

    so that it matches any character. You should probably read an introduction to regular expressions, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a little function in my app. I am currently playing
I'm trying to implement a function that have to return the minimum value from
I'm trying to implement a function that will read from a byte array (which
I'm trying to implement the blog this function from Flickr using the BloggerAPI to
I'm trying to implement a function which would load a server-stored CSV file, and
I am trying to implement a function which reads from Serial Port ( Linux)
I was trying to implement facebook logout functionality for my django app. In my
I'm trying to implement ping function in MonoTouch. for some reasons, Ping class from
I am trying to implement infer_class function that, given a method, figures out the
I'm trying to implement the GetHttpContext function from HtmlHelperTest.cs in VB.NET using Rhino Mocks,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.