Android client multi-File upload

Source: Internet
Author: User

In web development, multi-file upload is very convenient, directly using the HTTP protocol to submit data. The format is as follows:

   <form method=post action= "Http://192.168.1.101:8083/upload/servlet/UploadServlet" enctype= "Multipart/form-data ">            <input type=" text "name=" NAME ">            <input type=" text "name=" id ">            <input type=" File " Name= "ImageFile"/>            <input type= "file" name= "Zip"/>         </FORM>

But in the Android client, if the text and file upload together is more troublesome, need to be familiar with the HTTP protocol can do.

First, the HTTP protocolHTTP protocol is a very complex process, when we do web development, the underlying is actually encapsulated, can be used, all we need to do is to be familiar with the HTTP request format.The HTTP protocol is divided intoRequest MethodURIProtocol/version, request header, request body.
<span style= "White-space:pre" ></span>get/sample.jsphttp/1.1                    //Request method/Request Path/protocol version <span style= " White-space:pre "></span>accept:image/gif.image/jpeg,*/*          <span style=" White-space:pre "></ Span>accept-language:zh-cn<span style= "White-space:pre" ></span>connection:keep-alive<span Style= "White-space:pre" ></span>host:localhost<span style= "White-space:pre" ></span> user-agent:mozila/4.0 (compatible; MSIE5.01; Window NT5.0) <span style= "White-space:pre" ></span>accept-encoding:gzip,deflate<span style= " White-space:pre "></span>username=jinqiao&password=1234
This is a complete HTTP request.The requested protocol header mainly includes the following content:There is a space between the request header and the request body, which indicates that the request header has ended, and the following is the request body. Response header:This is the entire HTTP request.
Second, multi-file upload in AndroidThe use of HTTP GET or Post methods to submit data in Android has been described in the previous article.
The code has been posted in the Struts upload file article.
In the code, we need to do our own full construction of the entire HTTP request format.But there is a different place;the first is content-type:multipart/form-data;boundary=---------------------------7da2137580612;Because the form type is:multipart/form-data, the upload file is not the HTTP protocol, not the Name= "-" way, but the use of Separators Field Contents Separators Field Contents For example: Request Header---------------------------7da2137580612
Content-disposition:form-data;name= "username"

Zhuzg
---------------------------7da2137580612 content-disposition:form-data;name= "image";filename= "123.jpg" Content-type:application/octet-stream
---------------------------7da2137580612-----------//End Flag

Android client multi-File upload

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.