how to upload an image to server using API from android using ion library? I don't know much about ion library.
Asked
Active
Viewed 222 times
2 Answers
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
-
Is "salonPhotos" meant the name of the imageview? – Jibin Nov 29 '18 at 10:47
-
its the arraylist of image files. – Pemba Tamang Dec 01 '18 at 04:12
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