I'm a newbie with android studio. I want to upload an image to a server without converting it into a base64 string. I don't know how to do this. Here is my code:
//This is my code
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
HttpClient Client = new DefaultHttpClient();
HttpPost Post = new HttpPost("url/uploadphoto.php");
Log.d("HTTPPSt", "" + Post);
// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(1);
nameValuePair.add(new BasicNameValuePair("image", bitmap));
// Url Encoding the POST parameters
try {
Post.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = Client.execute(Post);
StatusLine statusLine=response.getStatusLine();
// writing response to log
Log.d("Http Response:", response.toString());
Log.d("statusline:", ""+statusLine);
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
I have this problem:
nameValuePair.add(new BasicNameValuePair("image", bitmap));
I can not send the bitmap instead I get an error.