Retrofit 2 Multipart POST request sends extra quotes to PHP

后端 未结 4 1840
广开言路
广开言路 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:25

    If you would rather not use a converter, here's what I did to send a multipart request containing an image file, and 2 strings:

    @Multipart
    @POST("$ID_CHECK_URL/document")
    fun postMultipart(@Part imageFile: MultipartBody.Part, @Part string2:  MultipartBody.Part, @Part string2:  MultipartBody.Part)
    

    And calling it this way:

        val body = RequestBody.create(MediaType.parse("image/jpg"), file)
        val imageFilePart = MultipartBody.Part.createFormData("file", file.name, reqFile)
    
        val string1Part = MultipartBody.Part.createFormData("something", "string 1")
    
        val string2Part = MultipartBody.Part.createFormData("somethingelse", "string 2")
    
        service.postDocument(imageFilePart, string1Part, string2Part)
    

提交回复
热议问题