Upload image with Ion android library

一个人想着一个人 提交于 2019-12-11 06:56:22

问题


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:


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);


来源:https://stackoverflow.com/questions/40412832/upload-image-with-ion-android-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!