How to do a same @Multipart POST call by sending an image, String fields and also an Array of objects?

Asked

Viewed 38 times

0

On a call, I register a professional, which involves sending your avatar, which appears in the first line as file and also send other attributes of the professional, for example, the place where he works.

This location is also saved in the database, and has a specific ID, so the object local possesses name and id.

Send strings as @Part it is easy, I had no problems. Send a string of objects local, however, it is challenging.

Can someone help me solve this?

P.S. The code is in Kotlin.

    @Multipart
    @POST("/profissional")
    fun postProfissional(
        @Part file : MultipartBody.Part,
        @Part("name") name: RequestBody,
        @Part("tempoPro") tempoPro: RequestBody,
        @Part("address") address: RequestBody,
        @Part("addressNumb") addressNumb: RequestBody,
        @Part("city") city: RequestBody,
        @Part("state") state: RequestBody,
        @Part("cep") cep: RequestBody,
        @Part("birthDate") birthDate: RequestBody,
        @Part("email") email: RequestBody,
        @Part("pass") pass: RequestBody,
        @Part("phone") phone: RequestBody,
        @Part("Local") saloesQueAtua: ArrayList<Local>?,
        @Part("services") services: ArrayList<RequestBody>?
    ): Call<ResponseBody>

Local Class:

class Local(
    var id : String?,
    var salao : String?
)
  • It is not clear what the problem is. It is giving some error when you make this request?

  • No mistake, it compiles and accepts the request... but nay the field "saloesQueAtua" contains nothing... is forwarded as containing only {}. How you would send an image along with other fields, one of which is an array of objectcs?

  • Convert everything to Base64 and convert on the other side

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.