I am developing small android application in which I wanted to upload image from my android device to my server. I am using HttpURLConnection
for that.
I am doing this in following way:
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow_down_float);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "image/jpeg");
connection.setRequestMethod(method.toString());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
bout.write(data);
bout.close();
I am using ByteArrayOutputStream
but I don't know how to pass that data with my httpurlconnection. Is this the correct way to pass raw image data. I just wanted to send byte array which contains image data. No conversion or no multipart sending.
My code working fine without any error but it my server gives me reply
{"error":"Mimetype not supported: inode\/x-empty"}
I did this with httpclient using setEntity
and its working fine with that. But I want to use urlconnection.
Am I doing something wrong? How to do this? Thank you.
client.setEntity(new ByteArrayEntity(data));
is there any way to do simillar in urlconnection. Need help. Thank you. – nilkash Mar 22 '13 at 4:28