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 943029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:22:14+00:00 2026-05-15T22:22:14+00:00

Let me start off by saying, I’m using the twisted.web framework. Twisted.web ‘s file

  • 0

Let me start off by saying, I’m using the twisted.web framework. Twisted.web‘s file uploading didn’t work like I wanted it to (it only included the file data, and not any other information), cgi.parse_multipart doesn’t work like I want it to (same thing, twisted.web uses this function), cgi.FieldStorage didn’t work (’cause I’m getting the POST data through twisted, not a CGI interface — so far as I can tell, FieldStorage tries to get the request via stdin), and twisted.web2 didn’t work for me because the use of Deferred confused and infuriated me (too complicated for what I want).

That being said, I decided to try and just parse the HTTP request myself.

Using Chrome, the HTTP request is formed like this:

------WebKitFormBoundary7fouZ8mEjlCe92pq
Content-Disposition: form-data; name="upload_file_nonce"

11b03b61-9252-11df-a357-00266c608adb
------WebKitFormBoundary7fouZ8mEjlCe92pq
Content-Disposition: form-data; name="file"; filename="login.html"
Content-Type: text/html

<!DOCTYPE html>
<html>
  <head> 

...

------WebKitFormBoundary7fouZ8mEjlCe92pq
Content-Disposition: form-data; name="file"; filename=""


------WebKitFormBoundary7fouZ8mEjlCe92pq--

Is this always how it will be formed? I’m parsing it with regular expressions, like so (pardon the wall of code):

(note, I snipped out most of the code to show only what I thought was relevant (the regular expressions (yeah, nested parentheses), this is an __init__ method (the only method so far) in an Uploads class I built. The full code can be seen in the revision history (I hope I didn’t mismatch any parentheses)

if line == "--{0}--".format(boundary):
    finished = True

if in_header == True and not line:
    in_header = False
    if 'type' not in current_file:
        ignore_current_file = True

if in_header == True:
    m = re.match(
        "Content-Disposition: form-data; name=\"(.*?)\"; filename=\"(.*?)\"$", line)
    if m:
        input_name, current_file['filename'] = m.group(1), m.group(2)

    m = re.match("Content-Type: (.*)$", line)
    if m:
        current_file['type'] = m.group(1)

    else:
        if 'data' not in current_file:
            current_file['data'] = line
        else:
            current_file['data'] += line

you can see that I start a new “file” dict whenever a boundary is reached. I set in_header to True to say that I’m parsing headers. When I reach a blank line, I switch it to False — but not before checking if a Content-Type was set for that form value — if not, I set ignore_current_file since I’m only looking for file uploads.

I know I should be using a library, but I’m sick to death of reading documentation, trying to get different solutions to work in my project, and still having the code look reasonable. I just want to get past this part — and if parsing an HTTP POST with file uploads is this simple, then I shall stick with that.

Note: this code works perfectly for now, I’m just wondering if it will choke on/spit out requests from certain browsers.

  • 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-15T22:22:15+00:00Added an answer on May 15, 2026 at 10:22 pm

    You’re trying to avoid reading documentation, but I think the best advice is to actually read:

    • rfc 2388 Returning Values from Forms: multipart/form-data
    • rfc 1867 Form-based File Upload in HTML

    to make sure you don’t miss any cases. An easier route might be to use the poster library.

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

Sidebar

Related Questions

Let me start by saying, I like the border that chrome is using for
First off let me start by saying I am using CodeIgniter and the Facebook
Let me start off by saying I'm brand new to Android programming. I'm using
Let me start off by saying I don't want to print only the duplicate
First off, let me start by saying that I am totally new to working
Let me first start off, sorry for the confusing title. I didn't know how
First let me start off by saying I do not believe I am leaking,
To start off, let me clear the air by saying we are aware of
Let me start off by saying I had one DLL loading in just fine.
Let me start off by saying that I am completely new with WPF (this

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.