Upload multipart image data in JSON with Retrofit?

后端 未结 3 1708
清酒与你
清酒与你 2021-01-04 20:06

I would like to do a PUT request with this JSON body (containing a picture) and with Retrofit. I\'m using it under Android:

{
    \"Request\": {
        \"da         


        
3条回答
  •  萌比男神i
    2021-01-04 21:02

    Retrofit only takes multipart and requestbody for its multipart.

    Call loadLevel1halfIconswithImage(@Part("headerdata[relation][icon_type]") RequestBody icon_type, @Part("headerdata[relation][name]") RequestBody name, @Part MultipartBody.Part file);
    

    And then in java

     // MultipartBody.Part is used to send also the actual filename
     MultipartBody.Part body =  MultipartBody.Part.createFormData("headerdata[relation][relative_image]", fileUpload.getName(), requestFile);
    
    
    
    call = service.loadLevel1halfIconswithImage(icon_type, name, body);
    

提交回复
热议问题