truly working multipart uploads.

Tim Roberts timr at
Tue Nov 11 09:20:46 CET 2003

Hunter Peress <hfastjava at> wrote:

>I have been unable to write a script that can do (and receieve) a multipart form upload.
>Also, it seems that there really are differences between python's implementation and else's. 
>Can someone please prove me wrong with a script that works with itself AND with example 18-2
>from php:

Plop this script into a CGI directory somewhere, load it into your browser
and do the upload.  Use a text file; it echos the file back out to your
browser.  This uses the exact form from the web page.

#! /usr/local/bin/python

import os
import cgi

q = cgi.FieldStorage()

if not q.has_key('userfile'):
  print """\
Content-Type: text/html

<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">

  f1 = q['userfile'].filename
  if q['userfile'].file:
    contents = q['userfile']
    contents = q['userfile'].value

  print "Content-Type: text/plain"
  print "Filename = ", f1
  print "Here's the content:"
  print contents

- Tim Roberts, timr at
  Providenza & Boekelheide, Inc.

More information about the Python-list mailing list