Android uses the xutils frame to upload photos (one or more) and text, the server receives photos and text (no garbled characters)

Source: Internet
Author: User

Android upload pictures, here I used the more popular Xutils framework, the framework can be implemented file upload, file download, image caching, etc., to be researched.

Here is the code uploaded by the android segment:

Xutils.jar Download

String uploadhost= "Http://192.168.1.100:8080/ReceiveImgFromAndroid/ReceiveImgServlet";  Server receive address Requestparams params=new requestparams ();p arams.addbodyparameter ("msg", "Upload image"); Params.addbodyparameter ("Img1", New File (FilePath));  FilePath is the picture address sendimgtoserver (Params,uploadpath) that the mobile phone obtains;

This is the way to upload files in the Xutils framework:

Public  void Uploadmethod (final requestparams params,final String uploadhost) {http.send ( HttpRequest.HttpMethod.POST, Uploadhost, Params,new requestcallback<string> () {@Overridepublic void OnStart () { Upload start} @Overridepublic void onloading (long total, long Current,boolean isuploading) {//upload} @Overridepublic void Onsuccess (responseinfo<string> responseinfo) {//upload succeeded, the return value in this is the data returned by the server//using String result = Responseinfo.result get return value} @Overridepublic void OnFailure (httpexception error, String msg) {//upload failed}});}

On the top of the mobile phone to submit photos, next to write a server side.

The server side receives the mobile phone side to upload the photograph the method and receives the JSP interface to upload the photograph the way, is uses the Jspsmartupload_zh.jar package file. The simplest way to implement a servlet, in which call Smartupload class receive on the line, this also need to deal with the text to receive the garbled problem.

Here is the specific code:

Smartupload.jar Download

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android uses the xutils frame to upload photos (one or more) and text, the server receives photos and text (no garbled characters)

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.