My code is working for one image when I upload more then one image it show error to me .
Can anybody help me in getting out this problem?
Using below code I am able to upload single Image , but I want to upload more then one Image so please help how can I upload Images. Thanks
Here is my code
String image_path=imageUrl1;
GetData(myFiles);
}
});
}
public void GetData(String myFiles)
{
String image_retrive_url="http://tradewale.com/open/tradedata.php?submitType=PostAd";
pDialog = new ProgressDialog(PostAddActivity.this);
pDialog.setMessage(" Sending...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
Bitmap bitmap = BitmapFactory.decodeFile(myFiles);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream);
byte [] byte_arr = stream.toByteArray();
String image_str = Base64.encodeBytes(byte_arr);
final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
String Title = title.getText().toString();
String Description = description.getText().toString().trim();
String PhoneNumber = phonenumber.getText().toString();
String Email = email.getText().toString();
String Price = price.getText().toString();
nameValuePairs.add(new BasicNameValuePair("image",image_str));
nameValuePairs.add(new BasicNameValuePair("photo_url", image_retrive_url));
Thread t = new Thread(new Runnable()
{
@Override
public void run() {
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://tradewale.com/open/tradedata.php?submitType=PostAd");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
final String the_string_response = convertResponseToString(response);
}
catch(final Exception e)
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
Toast.makeText(PostAddActivity.this, "ERROR " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
System.out.println("Error in http connection "+e.toString());
}
}
});
t.start();
}
To send more image in webservice. You have to change in webservice
also. Add one more
parameter in service part. so you can be able to send more than one image in one time.
and get the base64
string of second image like e.g. img_str2
like :
String image_str = Base64.encodeBytes(byte_arr);
String image_str2 = Base64.encodeBytes(byte_arr2);
and named new parameter in service like image2
nameValuePairs.add(new BasicNameValuePair("image",image_str));
nameValuePairs.add(new BasicNameValuePair("image2",image_str2));
Here image
and image2
is 2 diff
. parameter for images. these parameter names must also have to be define in your service side code
.. so that service code can save your iamges.