Image Upload using Retrofit

Posted by Sachin Joshi
3
Jun 2, 2016
216 Views

maxrresdefault.jpg


We are assuming you are already familiar with Retrofit. If not then first go to this. We have used multipart request for uploading image on server using Retrofit.

Following are the simple and easy steps for image uploading using Retrofit:-


Step 1: Add required dependency in your module level gradle file for using Retrofit.


Step 2: Create an interface that contain an abstract method with return type Call<ResponseBody>.


Step 3: Create a class that contains following:-

  • Base url of your server.

  • Instance of OkHttpClient.Builder.

  • Instance of Retrofit.Builder.


Step 4: Now create an api manager class from where you will create a request, Inside your class create a method with whatever name you want (in my case it is uploadFile) do the following :

  • Create reference of the interface created in previous step.

  • Create request body with media type multipart.

  • Crate body for multipart request.

  • Create Request body.

  • Crate the instance of the call and


Read more about the Image Upload using Retrofit visit Findnerd.



Comments
avatar
Please sign in to add comment.