Android:androidannotations upload files, the network interface is so simple

Source: Internet
Author: User

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

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.