lundi 18 juillet 2016

How to upload multipart image data in JSON with retrofit 2 in android?

How can i upload image file along with my json.

My request JSON looks in the below format.

{
    "Request": {
        "first_name": "Josmy",
        "last_name": "J",
        "profile_image_attributes": {
            "image":"file"
        }
    }
}

In my gson class i am inputting values some what like this

public class Request implements Serializable {
    @SerializedName("first_name")
    private String firstName;
    @SerializedName("last_name")
    private String lastName;
    @SerializedName("profile_image_attributes")
    private MultipartBody.Part profileImageAttributes;
}

@Headers("Content-Type:application/json")
@POST(PSDApiconstants.REGISTRATION)
Observable<PSDSignUpResponseBean> registration(@Body PSDRegistrationRequestBean requestBean);

is there any way without changing the request to

  {
      "imag": "File",
      "first_name": "Josmy",
      "last_name": "J",
    }

Aucun commentaire:

Enregistrer un commentaire