Retrofit Multipart with Body

ⅰ亾dé卋堺 提交于 2019-12-10 14:38:20

问题


This is how the body for the call should look like (image field will be added).

{
"email":"test", "username":"test", "password":"test", "name":"test", "description":"Something...", "OAuthCredentialsTest":{
"client_id":23, "client_secret":"test" } }

I am using @PartMap as the body in my call:

Call<CreateUserResult> createUserPart(@PartMap Map<String, RequestBody> map);

And then when I enqueue the call:

File file = new File(signUpUser.getImagePath());
    RequestBody fileBody = RequestBody.create(MediaType.parse("image/*"), file);
    RequestBody fullName = RequestBody.create(MediaType.parse("text/plain"), signUpUser.getFullName());
    RequestBody email = RequestBody.create(MediaType.parse("text/plain"), signUpUser.getEmail());
    RequestBody username = RequestBody.create(MediaType.parse("text/plain"), signUpUser.getUsername());
    RequestBody password = RequestBody.create(MediaType.parse("text/plain"), signUpUser.getPassword());
    RequestBody desc = RequestBody.create(MediaType.parse("text/plain"), signUpUser.getDescription());

    Map<String, RequestBody> myMap = new HashMap<>();
    myMap.put("file\"; filename=\"" + file.getName(), fileBody);
    myMap.put("name", fullName);
    myMap.put("email", email);
    myMap.put("username", username);
    myMap.put("password", password);
    myMap.put("description", desc);

But, how can I include the OAuthCredentialsTest key and values part in my myMap?

来源:https://stackoverflow.com/questions/44225188/retrofit-multipart-with-body

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