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

  • Home
  • SEARCH
  • 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 8804311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:34:13+00:00 2026-06-14T01:34:13+00:00

I have a Django form with an fileupload. In the view I want to

  • 0

I have a Django form with an fileupload. In the view I want to pass this file to another server with an urllib post request.

I tried to put this file in an ordinary post variable like this.

views.py on first server:

def loadfile(request):
    server_url = "foo"

    class UploadFileForm(forms.Form):
        filename = forms.FileField()
    context['fileform'] = UploadFileForm()

    #after button is pressed
    if request.method == 'POST':
        upload_file(context, server_url, request.FILES['filename'])

    return render_to_response("bar")

def upload_file(context, server_url, image_data):
    #create a temp file to store image on sever
    temp = tempfile.NamedTemporaryFile()
    for chunk in image_data.chunks():
        temp.write(chunk)
    temp.flush()

    #build filename
    origfilename = str(image_data)
    extention = origfilename[origfilename.rfind("."):]
    filename = uuid.uuid4().hex + extention            

    #encode image so it can be send
    with open(temp.name, "rb") as f:
        data = f.read()
        encoded_string = base64.urlsafe_b64encode(data)
        url = "http://" + server_url + "/uploadimage?filename=" + filename
        urllib2.urlopen(url, "img_data="+encoded_string)
    temp.close()

This works if the downsteam server is also an django testserver, but with nginx/uwsgi I run into “bad gateway” errors. I think this is because the buffer size of uwsgi is to small.
So a solution would be to make an proper multipart post request.

The question is: How to easily create a multipart urllib request given a django fileupload request?

  • 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-06-14T01:34:14+00:00Added an answer on June 14, 2026 at 1:34 am

    Use the requests library:

    url = 'http://httpbin.org/post'
    files = {'file': open('report.xls', 'rb')}
    r = requests.post(url, files=files)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django form on my template like this: <form action=/my-page/ method=post name=my_form>{%
I am overriding the clean() method on a Django form. I want to have
I have a django form with two different submit buttons, on the view where
I have a Django form with a username and email field. I want to
I have a Django admin form. And now I want to fill it's initial
I have a problem in customizing labels in a Django form This is the
i have this Django application in which when user request for localhost:8000/time/ ,it is
I have django form and I am receiving from POST a date formated like
I have a (django-generated) form with the following content: <form action=./ id=my_form method=post> ...
I have a django form, with values initialized.But i dont want the values to

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.