[英]How to form a request dynamically using Android koush/ion
Ia trying to upload multiple images to server using android Ion library 尝试使用Android离子库将多个图像上传到服务器
Ion.with(ProgressBarUpload.this)
.load(URL)
.uploadProgressBar(progressBar)
.uploadProgressHandler(new ProgressCallback() {
@Override
public void onProgress(long downloaded, long total) {
uploadCount.setText("" + downloaded + " / " + total);
}
})
.setMultipartFile("uploaded_file", f)
.setMultipartParameter("name", "andrew")
.asString().setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
Toast.makeText(getBaseContext(), "" + result, Toast.LENGTH_SHORT).show();
}
});
}
});
Here in this request i need to add setMultipartFile("uploaded_file", f)
to the request dynamically as per how many images the user selects 在此请求中,我需要根据用户选择的图像数量将setMultipartFile("uploaded_file", f)
动态添加到请求中
To make file upload optional add it as a multipart part, then add file part to it dynamically 要使文件上传为可选,请将其作为多部分添加,然后动态添加文件部分
ArrayList<Part> filesParts = new ArrayList<>();
fileParts.add(new FilePart("uploaded_file",new File(path))); //dynamically add
then add .addMultipartParts(filesParts)
to the request 然后将.addMultipartParts(filesParts)
添加到请求中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.