1

I've got an app that is connected to a server through a restful API, but I need to upload an image to the server and I'm using Ion library, is there anyway to upload this image to the server?

Isaac Kennedy
  • 179
  • 1
  • 1
  • 11
  • Have you look answer on this http://stackoverflow.com/a/26144513/5241603. It shows how to Uploading multipart file with Koush Ion library, Image too. – K.Sopheak Nov 04 '16 at 02:36
  • So, If I got a JSON to upload to a server alongside the image, will it upload as part of the JSON or as a simple separate upload? @K.Sopheak – Isaac Kennedy Nov 04 '16 at 23:07

1 Answers1

3

You can use .setMultipartParameter("key","value") to upload image along with other text values as well..

If you need to upload many images, You can use the "Part" class to add multiple images.

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

for (int i = 0; i < myImages.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);
Ashwin Valento
  • 878
  • 1
  • 7
  • 14