OhhhThatVarun
OhhhThatVarun

Reputation: 4321

Post JSON Multipart-Data with retofit android

I'm trying to simulate this request as in this picture from my android device. It is working fine with my API if I try it with the postman.

enter image description here

This code I'm using which is not working

    @Multipart
    @POST("students/driver/signup")
    fun driverSignUp(
        @Part licenseImg: MultipartBody.Part, @Part insuranceImg: MultipartBody.Part,
        @Part vehicleImg: MultipartBody.Part, @Part("driver") driver: Driver
    ): Call<Void>

I have Driver model class with SerializedName and Expose annotation.

I'm getting this error when sending request from the android I'm using golang in my backend schema: invalid path "driver

Upvotes: 0

Views: 54

Answers (1)

SebastienRieu
SebastienRieu

Reputation: 1512

your class driver could not be a Part.

you should send a json representing the Driver and the service will be

@Multipart
@POST("students/driver/signup")
fun driverSignUp(
    @Part licenseImg: MultipartBody.Part, @Part insuranceImg: MultipartBody.Part,
    @Part vehicleImg: MultipartBody.Part, @Part driver: MultipartBody.Part
): Call<Void>

then you'll have to update your service to accept json for driver instead of 4 string representing it

Upvotes: 1

Related Questions