android – How to send and receive bitmap on restful server


Guys, I did some research and found very little content, I would like some tips because I've never done that. How do I send and receive a bitmap to a server? Do I order with JSon? Do I convert to base64? What is the best way to send and how should my method on the server be to receive? It cost


Simply submit as binary content.

String url = "";
File file = new File(Environment.getExternalStorageDirectory()
try {
    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost(url);

    InputStreamEntity reqEntity = new InputStreamEntity(
            new FileInputStream(file), -1);
    reqEntity.setChunked(true); // mande em pacotes separados se necessario
    HttpResponse response = httpclient.execute(httppost);

} catch (Exception e) {
    // Trate seu erro

Example adapted from this answer .

Scroll to Top