The network interface is so simple
Use HttpClient to upload files, you can refer to the blog: using httpclient for file upload
If the project uses androidannotation, it is very convenient to write the upload interface, such as before the Post interface
First refer to the previous blog, using Androidannotations for post requests.
- The following is a network interface for file uploads using androidannotations
@Rest"http://192.168.31.183:8080/SSHMySql/", converters = {GsonHttpMessageConverter.class})publicinterface FileService extends RestClientErrorHandling{ @Post("/upload.action") @Accept(MediaType.APPLICATION_JSON) ReqResult uploadFile(MultiValueMap<String, Object> params);}
Arguments are passed when called, where the "userimage" field is the server-side field that receives the file, desc is another parameter, and of course you can add additional parameters.
- The following code is called when the network interface is invoked
PublicReqresultPostuploadfile(String localfilepath,string desc) {Try{if(!NewFile (Localfilepath). Exists ()) {return NULL; } multivaluemap<string, object> params =NewLinkedmultivaluemap<string, object> (); Params.add ("Userimage",NewFilesystemresource (Localfilepath)); Params.add ("desc", DESC);returnFileservice.uploadfile (params); }Catch(Exception e) {E.printstacktrace (); }return NULL; }
The most necessary explanation here is that the value of the "Userimage" parameter is: New Filesystemresource (Localfilepath)
Android Development Alliance QQ Group:272209595
Not for commercial purposes without permission
Android:androidannotations upload files, the network interface is so simple