简体   繁体   中英

How to form a request dynamically using Android koush/ion

Ia trying to upload multiple images to server using android Ion library

 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM