Cameron Laird wrote at 2003-8-24 17:44 -0500:
I'll abbreviate this: in a Python script that processes a file upload, how do I express the name of the uploaded file-- that is, the name of the file the user selected with his browser? I expected I'd find this in something like context.REQUEST.get_header('CONTENT-DISPOSITION') or context.REQUEST.get_header('filename') or somesuch, but I'm just getting None from those.
When you upload a file via a browser form, the file is encapsulated in a "multipart/form-data" message. The headers describing the file are not in the HTTP request envelop (what you access by "REQUEST.get_header") but in the headers of the part. ZPublisher wraps an uploaded file in a "ZPublisher.HTTPRequest.FileUpload" instance. Its "filename" attribute contains the filename as passed by the browser (usually only the basename without the directory part (exception: broken IE)). Its "headers" attribute contains the headers of the part (of the "multipart") corresponding to the file. Dieter