Upload Image to Server in Android - Retrofit Tutorial with Source Code

preview_player
Показать описание
If this video helped you out, consider showing your support so that I can keep making free videos 🙂:

In this tutorial we will see how we can upload image to server using Retrofit in Android Studio. To upload image we have to use multipart/form-data. Multipart sends a single object(file) in divided in multiple parts, each part is separated by a boundary and has some portion of object’s data. Each part also has its own headers like Content-Type, Content-Deposition.
In this tutorial we use Retrofit as network library, as it has built in support for multipart. We will go through the following steps in this tutorial:
1. Add Dependencies to Gradle
2. Create Retrofit Instance
3. Create Upload API
4. Upload the Image

So we have seen how we can upload image to the server in Android using Retrofit, if you have any confusion please feel free to drop them in the comments below.

Рекомендации по теме
Комментарии
Автор

Works like a charm. Tnks a lot brother..

milanmalla
Автор

Excellent work ... Simple code but its Working

md.harunorrashid
Автор

its always going into onFailure method with this ) for android 9 version.please give me reply with answer

beltechnology
Автор

please make video for multiple image upload using retrofit and php

vasimkherani
Автор

can you share php api files to retrieve this..

ranjithjose
Автор

please I have a question, we will follow the same method if the server is spring boot or not??

xxmtnvw
Автор

Could.you please create a server that accepts the call.of the api

georgealbo
Автор

if we want to upload images to firebase with this can we do ?, , if we can do then how ?, ,

arttech
Автор

somebody borrow me a magnifier to see that code :))))
thanks a lot friend
just make your font size bigger :)

Roozbeh
Автор

how do I upload the bitmap directly without converting it to file??

upendsingh
Автор

i miss the part of layout part or what in you sources code no mainLayout? waste of time or lack of attention.

pablolarade
Автор

Error. Anchor trust certification not found

georgealbo
Автор

My code doesn't work on some mobile phones. Do you know what should I do? The result is null in this case!!

nickray
Автор

The return type should be 'ResponseBody', not 'RequestBody'

project_manager
Автор

What If I want to send multiple files ?

rattansingh
Автор

HI, I create Toast for both onResponse and onFailure to see whether the photo can be upload or not, but it seems like it is always on failure, how can I solve this?

mrclnotmrci
Автор

what exactly is the purpose of this video?

lucarocklv
Автор

Unfortunately, I can't dislike more than once

mohamed_akram
Автор

Could you please help me with the backend java rest api.. I tried with the below code but it is not working.
Kindly help

Retrofit

@Multipart

@POST("uploadFile")

Java Rest API

)

sanjeevmitra
Автор

i have watched 3 videos,
none of their description had link to get uri of file

naveennirban