I could not get this to work, so instead I used Base64 encoding and BasicNameValuePair and managed to upload it that way. 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.
Works fine now, code follows:
private void filesToSend() {
File f1=new File(id.getText().toString());
File f2=new File(ccd.getText().toString());
if (f1.exists()&&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;
}
The next part is in my AsyncTask:
protected String doInBackground(String... params) {
String result=null;
String response=null;
ArrayList<NameValuePair> postparams=new ArrayList<NameValuePair>();
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;
}
And then on button click:
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.");
}
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.