1

I am using params.put to post the strings to the server. But how do I post an image which is saved in the variable imgPreview.

comp_logo_id is the image field in Rest Api.

Here is My code:

            params.put("title", title);
            params.put("comp_logo_id", comp_logo_id);
            params.put("company_name", company_name);
            params.put("industry_selected", industry_selected);
nikita Yalgi
  • 37
  • 1
  • 1
  • 7

1 Answers1

0

You must convert image to base64 and upload to server . In server convert base64 to image .

  public String getEncoded64ImageStringFromBitmap(Bitmap bitmap) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 70, stream);
        byte[] byteFormat = stream.toByteArray();
        // get the base 64 string
        String imgString = Base64.encodeToString(byteFormat, Base64.NO_WRAP);

        return imgString;
   }
   String encodedImageData =getEncoded64ImageStringFromBitmap(your bitmap);
   params.put("comp_logo_id", encodedImageData );
Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98