Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I could not get this to work, so instead I used Base64 encoding and BasicNameValuePair and managed to upload it that way. <strong>Regardless, if someone has an idea about what was wrong with the code in the question, and how to fix it I would like to know.</strong></p> <p>Works fine now, code follows:</p> <pre><code>private void filesToSend() { File f1=new File(id.getText().toString()); File f2=new File(ccd.getText().toString()); if (f1.exists()&amp;&amp;f2.exists()) { Bitmap bip1=BitmapFactory.decodeFile(f1.getAbsolutePath()); Bitmap bip2=BitmapFactory.decodeFile(f2.getAbsolutePath()); ByteArrayOutputStream stream1=new ByteArrayOutputStream(); ByteArrayOutputStream stream2=new ByteArrayOutputStream(); bip1.compress(Bitmap.CompressFormat.JPEG, 90, stream1); //compress to which format you want. bip2.compress(Bitmap.CompressFormat.JPEG, 90, stream2); byte [] byte_arr1=stream1.toByteArray(); byte [] byte_arr2=stream2.toByteArray(); image_str1=Base64.encodeToString(byte_arr1, Base64.DEFAULT); image_str2=Base64.encodeToString(byte_arr2, Base64.DEFAULT); RSet=true; } </code></pre> <p>The next part is in my AsyncTask:</p> <pre><code>protected String doInBackground(String... params) { String result=null; String response=null; ArrayList&lt;NameValuePair&gt; postparams=new ArrayList&lt;NameValuePair&gt;(); postparams.add(new BasicNameValuePair("idpic", params[0])); postparams.add(new BasicNameValuePair("ccdpic", params[1])); try { response=CustomHttpClient.executeHttpPost(params[2], postparams); result=response.toString(); } catch (Exception e) { Log.e("Error", e.getMessage()); } return result; } </code></pre> <p>And then on button click:</p> <pre><code>filesToSend(); String url="http://10.0.2.2/Android/tstep.php"; if(RSet.equals(true)) { new MyAsyncTask().execute(image_str1, image_str2, url); } else if(RSet.equals(false)) { tostVLong("The images are not set, please choose or take a picture before sending."); } </code></pre> <p>PS I am using a custom http client I got from one of the answers on this site, just can't remember which one... Also tostVLong is a toast with show time extended.</p>
    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.
    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