Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 22.214.171.124 release ready!
Owner and Founder. Opencart
Retrofit is a very popular and great Network library for Android. Retrofit makes it easy to connect to a REST web service by translating the API into Java interfaces. In our previous blogs, we have already learned about starting with retrofit and how to upload a single file using retrofit. If you haven’t read those and want to know about it then you can follow the below provided links.
Using Retrofit library to make Http Requests
How to make a multipart request with dynamic URL using Retrofit
Now we will discuss uploading a dynamic number of files to the server. The main twist here is that you need to define @Part MultipartBody.Part file type parameter in your request.
Let us look at a sample code below for better understanding.
In the above code segment, We have defines two RequestBody type parameters and one List<MultipartBody.Part> type param. MultipartBody.Part contains the file and a List of MultipartBody.Part will contain multiple files which will be sent with the request.
Now let us create the List of files. Below is the sample code for it.
As you can see in the above code you can add string data to your request using the create function of the RequestBody class just add the MediaType as “text/plain”. To add the file, you need to get the URI of the file, create a file object with it, create a RequestBody object with the file, create MultipartBody.Part using the RequestBody object and add it to the list. You need to set the mime type in each RequestBody object according to the file.
And after creating all the requested data you can execute the request and will get the desired results.
Thank you very much. This is Vedesh Kumar signing off.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
And to send it after every 10 mins, You will have to start a service and you can get the task done.
Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.