Android 如何使用ion库中的多部分文件上载请求发送正文参数?

Android 如何使用ion库中的多部分文件上载请求发送正文参数?,android,ion,Android,Ion,这是我第一次使用多部分请求在服务器上上载数据。我正在使用ion for service hit。您能告诉我如何在服务器上发布我的数据吗? 这是我的请求参数 jSON Request: {s_id note_name file_name tag_name set_date mark_as_done clear_reminder Description media_name1 media_name2 media_name3 Count = 3 } 同时,我还必须将文件med

这是我第一次使用多部分请求在服务器上上载数据。我正在使用ion for service hit。您能告诉我如何在服务器上发布我的数据吗? 这是我的请求参数

jSON Request:
 {s_id 
note_name
 file_name 
tag_name 
set_date 
mark_as_done
 clear_reminder
 Description 
media_name1 
media_name2
 media_name3
 Count = 3 }

同时,我还必须将文件media1、media2、media2上传到同一个api**。任何帮助都将不胜感激。谢谢你不能在一个HTTP请求中完成JSON正文和多部分正文

您可以将json作为参数发送:)

//首先创建json对象
JsonObject对象=新的JsonObject();
addProperty(“注意你的名字”,“你的值在这里”);
addProperty(“描述”,“您的描述在这里”);
//在此处添加其他内容
//创建要上载的文件列表
列表文件=新的ArrayList();

对于(int i=1;我仍在寻找您的重播。。。
// first create your json object
    JsonObject object = new JsonObject();
    object.addProperty("note_name", "your value goes here");
    object.addProperty("description", "your description goes here");
    // add other stuffs here

    //create list of files to upload
    List<Part> files = new ArrayList<>();
    for (int i = 1; i <= 3; i++) {
        files.add(new FilePart("file" + i, new File("path of file like: storage/image/....")));
    }

    Ion.with(context)
            .load("POST","http://example.com")
            .uploadProgress(new ProgressCallback() {
                @Override
                public void onProgress(long downloaded, long total) {
                    int percent = (int) (downloaded * 100 / total);
                    // update your progressbar with this percent if needed
                }
            })
            .addMultipartParts(files)
            .setMultipartParameter("json", object.toString()) // your json is here
            .asString()
            .setCallback(new FutureCallback<String>() {
                @Override
                public void onCompleted(Exception e, String result) {
                    if (e != null) {
                        // error: log the message here
                        return;
                    }
                    if (result != null) {
                        // result is the response of your server
                    }
                }
            });