Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid gallery image to base 64 string
    primarykey
    data
    text
    <p>My app allows a user to select an image from the gallery and upload it to a server. Currently I can display the image but not upload it. I am not getting an error. Below is my code, I hope that it is clear.</p> <pre><code>public void submit_click(View view) { TextView err=(TextView) findViewById(R.id.err); if (thumbnail != null) { // TextView err = (TextView) findViewById(R.id.err); try{ byte[] bitmapdata = imagetoArray(); img = decodeUTF8(bitmapdata); if (updateImage() == true) { Intent myIntent = new Intent(view.getContext(), ProfileActivity.class); startActivityForResult(myIntent, 0); } else { err.setText("Error update image"); } } catch(Exception ex) { err.setText(ex.getLocalizedMessage()); } } } private boolean updateImage() { boolean status = false; TextView err=(TextView) findViewById(R.id.err); String username = SessionManager.getMaps("user"); String postData = "{\"UserImage\":\"" + img + "\",\"UserName\":\"" + username + "\"}"; try { String domain = getString(R.string.domain); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; HttpPost httppost = new HttpPost(domain + "updateUserImage"); StringEntity se = new StringEntity(postData.toString(), "utf-8"); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); httppost.setHeader("Accept", "application/json"); httppost.setHeader("Content-type", "application/json"); response = httpclient.execute(httppost); if (response != null) { HttpEntity r_entity = response.getEntity(); String json = EntityUtils.toString(r_entity); status = Boolean.parseBoolean(json); } } catch (Exception e) { err.setText(e.getLocalizedMessage()); } return status; } private byte[] imagetoArray() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); TextView err=(TextView) findViewById(R.id.err); try{ thumbnail.compress(Bitmap.CompressFormat.PNG, 100, stream); } catch(Exception ex) { err.setText(ex.getLocalizedMessage()); } return stream.toByteArray(); } private String decodeUTF8(byte[] bytes) { String sw=""; TextView err=(TextView) findViewById(R.id.err); try{ sw= Base64.encodeToString(bytes, Base64.NO_WRAP); } catch(Exception ex) { err.setText(ex.getLocalizedMessage()); } return sw; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload