Adnroid: how to upload images to WebService (written in C)

Source: Internet
Author: User
These days, I have been writing the adnroid mobile editing system for the first time because I encountered many problems when using Java and Android platforms: <1> how to call it. net-written WebServices <2> how to browse images (imageview) <3> how to get the image name and path has been solved. It took me several days to explain how to solve the problem of adnroid uploading images to WebService (C) webServices method: (this is not very critical, we will usually handle) the definition of the view code parameter: String uploadphoto (string strxml, byte [] photodata, int length) method Body key Code : (Restore byte [] type variables to files) filestream FS = new filestream (sfilepath + "\" + filename, filemode. openorcreate, fileaccess. readwrite, fileshare. readwrite); FS. position = position; FS. write (bytes, 0, bytes. length); FS. close (); FS = NULL; copy the code Android client (sdk2.2) code. I just want to talk about how to generate the second parameter (the key to the problem is here) @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); requestwindowfeature (window. feature_no_title); setcontentview (R. layout. tupiangaojian); // imageview iv_image = (imageview) findviewbyid (R. id. imview); iv_image.setdrawingcacheenabled (true); // This sentence is equivalent to Bitmap bitmap = iv_image.getdrawingcache (); corresponding to //} // obtain the base64 encoded string of the image (Bitmap variable from the imageview can obtain Bitmap bitmap = iv_image.getdrawingcache ();) bytearrayoutputstream baos = new bytearrayoutputstream (); bitmap. compress (bitmap. compressformat. PNG, 100, baos); string photodata = new string (base64.encode (baos. tobytearray (), base64.default); string uploadphoto (string strxml, byte [] photodata, int length) here, photodata is the data to be uploaded to the photodata parameter (interestingly, the parameter defines byte [] and the variable is string) this problem has been plagued for several days and finally solved in this way. By the way, record other things: how to get the image file name (imageview) view code @ override protected void onactivityresult (INT requestcode, int resultcode, intent data) {If (resultcode = result_ OK) {URI uri = data. getdata (); cursor = getcontentresolver (). query (Uri, null, null); cursor. movetofirst (); // string imgno = cursor. getstring (0); // The image number imgpath = cursor. getstring (1); // image file path string imgsize = cursor. getstring (2); // image size string imgname = cursor. getstring (3); // image file name }}

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.