0

how to upload an image to server using API from android using ion library? I don't know much about ion library.

Jibin
  • 1
  • 2

2 Answers2

0

As answered by @Ashwin Valento here you need to do this.

ArrayList<Part> fileParts = new ArrayList<>();

for (int i = 0; i < salonPhotos.size(); i++) {
    Part part = new FilePart("image_name[" + i + "]",image_value[i]);
    fileParts.add(part);
}


Ion.with(getContext())
.load("POST", MY_POST_URL)
.setMultipartParameter("my_text_key", "my_text_value")
.setMultipartParameter("my_text_key_2", "my_text_value_2")
.addMultipartParts(fileParts);

Here the image is being sent as a part of multipart form data to the server. Or you could send the image in base64 format like here. It's pretty straight forward.

Pemba Tamang
  • 1,235
  • 16
  • 38
0

My original answer is here which explains how you can upload multiple images.

If your requirement is to upload a single image, then you can do as

Ion.with(getContext())
.load("POST", MY_POST_URL)
.setMultipartFile("image", "image/png", new File("/sdcard/some_image.png"))
Ashwin Valento
  • 878
  • 1
  • 7
  • 14