The Android side uses the volley request base class to implement several of its methods to upload files in a mosaic form
The server side uses the spring framework to receive files.
One, Android: three categories: Mainactivity,postrequest,uploadfilerequest.
1.PostRequest inherits from Request<string>, realizes its deliverresponse and Parsenetworkresponse as well as getparams three methods,
Constructor is
Public Postrequest (String url,map<string,string>params, Responselistener Listener) {...}
2.UploadFileRequest inherits from Postrequest, implements its GetBody () and Getbodycontenttype () methods, getbody to splice form data, Getbodycontenttype is used to return the form type:
Return "multipart/form-data;boundary=------8d74g45h";
Constructor is
Public uploadfilerequest (String URL, list<fileform>filelist, Responselistener Listener) {...}
3. Call Uploadfilerequest in mainactivity and add it to the volley queue.
@Controller public
class Uploadcontroller {
@RequestMapping ("Uploadimage")
//@ResponseBody
Public void AddImage (HttpServletRequest request) throws IllegalStateException, ioexception{
Multiparthttpservletrequest multiparthttpservletrequest = (multiparthttpservletrequest) request;
Multipartfile file = Multiparthttpservletrequest.getfile ("UploadFile");
if (!file.getoriginalfilename () ==null) {
file TargetFile = new file ("F:/789.png");
File.transferto (targetfile);
}
Second, the server side:
When using Multiparthttpservletrequest, remember to add the multipart parser to the spring configuration file:
@Controller public
class Uploadcontroller {
@RequestMapping ("Uploadimage")
//@ResponseBody
Public void AddImage (HttpServletRequest request) throws IllegalStateException, ioexception{
Multiparthttpservletrequest multiparthttpservletrequest = (multiparthttpservletrequest) request;
Multipartfile file = Multiparthttpservletrequest.getfile ("UploadFile");
if (!file.getoriginalfilename () ==null) {
file TargetFile = new file ("F:/789.png");
File.transferto (targetfile);
}
This completes the file upload operation.
Reference:
1.Spring File Upload processing: http://amcucn.iteye.com/blog/264457
2.Volley File Upload operation: http://blog.csdn.net/jxxfzgy/article/details/44064481