Retrofit 2 Multipart POST request sends extra quotes to PHP

后端 未结 4 1826
广开言路
广开言路 2021-02-05 17:08

Using Retrofit 2.0.1, there is a call function in my API interface defined in Android App:

@Multipart
@POST(\"api.php\")
Call doAPI(
  @Part(         


        
4条回答
  •  借酒劲吻你
    2021-02-05 17:41

    Use RequestBody for all your parameters. Please go through below code!!

    File file = new File(imagePath);
    RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
    MultipartBody.Part imageFileBody = MultipartBody.Part.createFormData("media", file.getName(), requestBody);
    RequestBody id = RequestBody.create(MediaType.parse("text/plain"),addOfferRequest.getCar_id());
    ApiCallback.MyCall myCall = apiRequest.editOfferImage(imageFileBody,id);
    

    Use RequestBody class of Retrofit instead of String

    @Multipart
    @POST(ApiURL)
    ApiCallback.MyCall editOfferImage(@Part MultipartBody.Part imageFile,@Part("id") RequestBody id);
    

提交回复
热议问题