Content parsing when HTTP POST Form-data

Source: Internet
Author: User
Tags http post

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.