Upload image with Ion android library

2019-08-03 00:50发布

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?

1条回答
祖国的老花朵
2楼-- · 2019-08-03 01:22

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);
查看更多
登录 后发表回答