1

I need to upload image file on Server using HttpGet Method.Please help me out. Thanks

3 Answers3

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(); 
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