Android Upload Multiple Files In A Single Request

后端 未结 2 1623
不知归路
不知归路 2021-01-21 03:34

I\'m posting content to the server in a multipart/form-data request. and the data I\'m posting contains multiple parameters including a file array parameter (files[]).

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 03:51

    I think you should change the MediaType for file. and you also check the link for that https://futurestud.io/tutorials/retrofit-2-how-to-upload-files-to-server and for send file with @Part MultipartBody.Part

    MediaType mediaTypeForText = MediaType.parse("text/plain"); 
    MediaType mediaTypeForImage = MediaType.parse("image/*");
    
    Map params = new HashMap<>(); 
    params.put("first-parameter", MultipartBody.create(mediaTypeForText, "first-parameter-value")); 
    params.put("second-parameter", MultipartBody.create(mediaTypeForText, "second-parameter-value")); 
    params.put("files[0]", MultipartBody.create(mediaTypeForImage, new File(fileUri.getPath())); 
    params.put("files[1]", MultipartBody.create(mediaTypeForImage, new File(fileUri.getPath()));
    

提交回复
热议问题