The HTTP protocol process when uploading a file form
First, upload the file code as a form in the browser as follows
<form action= "/api/uploads" method= "POST" enctype= "Multipart/form-data" >
<div class= "Form-group" >
<input type= "File" class= "Form-control-file" name= "File" >
<input type= "Submit" value= "Upload" >
</div>
</form>
Due to the provisions in the HTTP protocol, enctype must be multipart/form-data, and the name in file input will be the uploaded parameter, the uploaded file name is model.py below the request message header shown in Firefox
Post content is as follows
Boundary is used to split the post content of different parts of the file, in the content we see that the parameters in the content-disposition after the name and filename are the parameters of the input selected in the fill parameters, Russia and Japan behind the Content-type is the document content. The separators shown below can be divided into different sections. The parameters are wrapped in flask's request, all the files passed are in Request.Files, can be selected by Request.files[name], or by Request.files.items () Gets an iterator.
The contents of post content are similar when the contents of a form are present in files and other data, first we look at the following code
<form action= "/api/uploads" method= "POST" enctype= "Multipart/form-data" >
<div class= "Form-group" >
<input type= "File" class= "Form-control-file" name= "File" >
<input type= "text" name= "T1" >
<input type= "text" name= "T2" >
<input type= "Submit" value= "Upload" >
</div>
</form>
The content in post is as follows
Each field of the form is split separately, and the form stores the name and content in Flask's request, but the file is not stored in the form and stored in the request.files.
Content parsing when HTTP POST Form-data