I'm using this method to upload files to my server:
@Multipart
@POST("new")
Call<Response> send(@Part("myFile") byte[] file);
I have been reading and some people use TypedFile
to do it, and maybe this is easier than send raw bytes like I'm doing.
TypedFile
class is in retrofit.mime
package. But I don't have it there. Has this package been removed from 2.0 version? Or do I have to add another dependency? If so, which one?
Thanks.
I use its solution : API Service: @POST("trip/{tripId}/media/photos") Call<MediaPost> postEventPhoto( @Path("eventId") int tripId, @Header("Authorization") String accessToken, @Query("direction") String direction, @Body RequestBody photo);
In 2.0 you need to use RequestBody instead of TypedFile. Get file with RequestBody
RequestBody file = RequestBody.create(MediaType.parse("image/*"), path);
Use it in your request
@Multipart
@POST("new")
Call<Response> send(@Part("myFile") RequestBody file);
More info https://github.com/square/retrofit/issues/1063
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With