i think i know step 1 :)
data =
environ['wsgi.input'].read(int(environ.get('CONTENT_LENGTH','0')))
Combine with cgi.FieldStorage.
http://docs.python.org/lib/module-cgi.html
Pass 'wsgi.input' as fp and environ as headers. From memory, something like:
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
This can be use for file uploads as well as form posts in general.
Graham
ohoh found out how to split it up into smile peaces :)
from http://code.djangoproject.com/ticket/2613
mem = StringIO()
input = self.environ['wsgi.input']
content_length = int(self.environ["CONTENT_LENGTH"])
chunksize = 65536
while true:
remain = content_length - mem.tell()
if remain <= 0: break
chunk = input.read(min(chunksize, remain))
if not chunk: break
mem.write(chunk)
data = mem.getvalue()
mem.close()
So whats the part i do with the data ?
It has provision for writing uploaded files to disk. You can create
derived version of it to better control where files are put and
whether they are unlinked immediately.
You really need to read the documentation and look at the source code
to work out if it meets you requirements.
If you don't need the file upload as part of form data. then you can
just read from wsgi.input and write it out to files how you want.
Graham
ok i think i will do it manual and figure out how the data is sent.
Where can i find the cgi multifile format ? So i know where to look
for in the wsgi.input
If you are just going to take the complete body of the request as a
file, you don't need to know about typical POST encodings. I can't
remember off hand though what you need to stick in your web page to
trigger content of request being untouched file content.
If you are going to use traditional POST encodings, do not try and
implement it yourself, use the cgi module and work out how to
customise its behaviour as necessary.
As to the actual format, if you still want to know, then it is the
subject of various Internet standards. I don't remember which is the
primary standard, but start with:
http://www.ietf.org/rfc/rfc2046.txt
Also, since this is now becoming a general programming problem and not
mod_wsgi specific, I would suggest you use the group:
http://groups.google.com/group/comp.lang.python/topics
You will find a lot more people there who can give a better answer.
Just don't muddy the waters by mentioning mod_wsgi as this is a basic
HTML/CGI level problem, mention mod_wsgi and people will probably
think your after something different and not answer. You will also
need to make sure you have read the cgi module documentation and tried
a few things before you go asking stuff, otherwise you will probably
just get back answers to read the documentation again. You need to
show that you have actually tried something but then are getting stuck
for some reason in understanding it.
Graham
On Oct 29, 10:21 pm, "Graham Dumpleton" <graham.dumple...@gmail.com>
wrote:
Ok got it, plain old cgi format no wsgi modifications
PS one last thing for what it is worth for others
s=environ['wsgi.input'].read(int(environ.get('CONTENT_LENGTH','0')))
f = open('C:/Program Files/Apache/trunk/wsgi/upload.txt','w')
f.write(s)
found out that it gives a very nice text file of raw data that comes
in so you have a better look about the cgi puzzel :)
http://en.wikipedia.org/wiki/Image:Superb_fairy_wren2_LiquidGhoul.jpg
puts all files in a data list
b=environ.get('CONTENT_TYPE','0')
b=re.compile('boundary=(.*)').search(b).group(1)
r=re.compile(b+r"\r\n(.*?)\r\n(.*?)\r\n\r\n(.*?)\r\n--"+b,
re.DOTALL)
s=environ['wsgi.input'].read(int(environ.get('CONTENT_LENGTH','0')))
data=[]
start=0
while 1:
m=r.search(s,start)
if m:
data.append(m.group(3))
start=m.end()-len(b)
else: break