0

I have a post request where I send data using hashmap but now I want to send multiple images too in the request. here is my interface

@POST("/my-api")
fun createEditObject(@Body requestMap: HashMap<String, Any?>): Call<Object>

I did not get any solution regarding this problem.

Rimsha Butt
  • 115
  • 8
  • please check this one https://stackoverflow.com/a/39911454/7846071 – Nensi Kasundra Apr 13 '20 at 11:20
  • @NensiKasundra Can you help? https://stackoverflow.com/questions/62783444/why-does-multipart-pdf-is-not-able-to-upload-in-api-using-retrofit-2-in-android?noredirect=1#comment111031344_62783444 – Priyanka Singh Jul 08 '20 at 07:28

1 Answers1

0

you need to annotate your post request with @Multipart and pass MultipartBody.Part in your createEditObject method like that.

@Multipart
@POST("/my-api")
fun createEditObject(@Body requestMap: HashMap<String, Any?>, @Part file: MultipartBody.Part): Call<Object>

now you can create your file parameter like that.

val file = File(filePath)
val reqBody = RequestBody.create(MediaType.parse("image/jpeg"), file)
val part = MultipartBody.Part.createFormData(NAME, FILE_NAME, reqBody)