I need to upload image file on Server using HttpGet Method.Please help me out. Thanks
Asked
Active
Viewed 1,073 times
1
-
You have to use httpPost request. – Nitesh Nov 29 '14 at 09:22
3 Answers
0
use http post request ...convert image to byte array and then send it to server
InputStream is = this.getAssets().open("image.png");
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest =
new HttpPost("http://webserver.com/doSomething.do");
byte[] data = IOUtils.toByteArray(is);
InputStreamBody isb = new InputStreamBody(new
ByteArrayInputStream(data), "uploadedFile");
StringBody sb1 = new StringBody("some text goes here");
StringBody sb2 = new StringBody("some text goes here too");
MultipartEntity multipartContent = new MultipartEntity();
multipartContent.addPart("uploadedFile", isb);
multipartContent.addPart("one", sb1);
multipartContent.addPart("two", sb2);
postRequest.setEntity(multipartContent);
HttpResponse response =httpClient.execute(postRequest);
response.getEntity().getContent().close();

Munawwar Hussain Shelia
- 1,364
- 9
- 12
0
As already hinted by Nitesh, in order to upload image file you should use a Post request and submit your file as binary.
Please refer below link in SO for more details: How do I send a file in Android from a mobile device to server using http?

Community
- 1
- 1

AADProgramming
- 6,077
- 11
- 38
- 58
0
Try this
String _URL =https://194.1.3.9:7721/request?image_byte=iamge _inbyte;
HttpClient client = getHttpClient();
HttpPost request = new HttpPost(_URL);
HttpResponse response = client.execute(request);
private static HttpClient getHttpClient() {
if (mHttpClient == null) {
mHttpClient = new DefaultHttpClient();
final HttpParams params = mHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
}
return mHttpClient;
}

DJhon
- 1,548
- 3
- 22
- 39
-
Very funny to try to put bytes in an url and then do an empty post. Very funny indeed. – greenapps Nov 29 '14 at 10:47