truly working multipart uploads.

H

Hunter Peress

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: http://www.php.net/manual/en/features.file-upload.php



__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
 
L

Lee Harr

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: http://www.php.net/manual/en/features.file-upload.php

I have seen some discussions related to this question recently
on the python web-sig mailing list:
http://mail.python.org/pipermail/web-sig/
 
A

Andrew Clover

Hunter Peress said:
Also, it seems that there really are differences between python's
implementation and else's.

Why do you say that? I know of no problems with receiving file uploads
fields in either the standard cgi module or my own replacement for it;
if you are talking about *sending* multipart/form-data requests, what
software are you using to create them?

The main 'gotcha' with sending and receiving form-data is that with
Windows, stdin and stdout are not by default binary streams, so could
corrupt newline characters if they are in the file, causing parsing
problems. If you are using Windows, ensure you have binary streams
(eg. with python -u).
 
T

Tim Roberts

Hunter Peress said:
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: http://www.php.net/manual/en/features.file-upload.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 php.net web page.


#! /usr/local/bin/python

import os
import cgi

q = cgi.FieldStorage()

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

<html><head><title>Testing</title></head>
<body>
<form enctype="multipart/form-data" action="x.py" 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">
</form>
</body>
</html>"""

else:
f1 = q['userfile'].filename
if q['userfile'].file:
contents = q['userfile'].file.read()
else:
contents = q['userfile'].value

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top