how to send image (bitmap) to server in android with multipart-form data json

前端 未结 2 1821
抹茶落季
抹茶落季 2020-12-08 11:51

I have code to upload image to server and it works ,

HttpEntity resEntity;

                HttpClient httpClient = new DefaultHttpClient();
                        


        
2条回答
  •  眼角桃花
    2020-12-08 12:26

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    photo.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    

    Then send this encodedImage as a String and in your server you will need to decode it in order to get the image itself.

提交回复
热议问题