Python: parse HTTP POST request with file upload and additional parameters

The task is simple: on the server side (python) accept HTTP POST, which contains the downloaded file and other form parameters.

I am trying to implement a download progress indicator, and therefore I need to be able to read the contents of the file block by block.

All the methods I found are based on cgi.FieldStorage, which somehow only allows me to get the whole file (in memory, which in itself is a disaster). Some recommend overriding the FieldStorage.make_file () method, which seems to destroy the cgi implementation (weird ...).

Currently, I can read all the input of wsgi, chunk by chunk, into the file system, resulting in the following data:

-----------------------------9514143097616
Content-Disposition: form-data; name="myfile"; filename="inbound_marketing_cartoon_ebook.pdf"
Content-Type: application/pdf

... 1.5 MB of PDF data

-----------------------------9514143097616
Content-Disposition: form-data; name="tid"

194
-----------------------------9514143097616--

- , Python, ? ? (Python 2.5, )

.

+3
3

, ( ) make_file FieldStorage. , write, ( --) , .

, ( ), , .

, , CGI ?

- - (YUI Uploader SWFUpload ) . AJAX .

+2

( , ), email, , , . , ; RFC 2822 , email, , .

email , .

, , , , , .

+1

You might want to take a look at what Django has done. They have a really good implementation of custom file upload handlers, which allows them to be subclassed to include elements such as progress bars, etc. See the documentation and related code - even if you don't want to use Django, it should give you some ideas.

0
source

Source: https://habr.com/ru/post/1719830/


All Articles