Android Upload Image to Server Using Volley

Here you will learn about android upload image to server using volley library.

At server side I have used java web service and for sending image to server volley library is used.

How it works?

  • The user chooses an image from gallery and click on upload button.
  • The image is then converted into Base64 string format and sent to server using volley network library.
  • Now at server side this Bas64 string is converted back into image and stored at some location.

 

Android Upload Image to Server Using Volley

Server Code

Below is the code for server. It is a java web service. If you don’t know how to make web service in java then read below tutorial.

Also Read: Create Simple Java RESTful Web Services Using Jersey

DemoService.java

 

Android Project

1. Now create a new android project with package name com.androiduploadimage

 

2. Add dependency for volley library by adding following line in build.gradle file.

 

3. Add internet access permission in AndroidManifest.xml file.

 

4. Add following code in respective files.

activity_main.xml

 

MainActivity.java

 

Screenshot

Android Upload Image to Server Using Volley

You can ask your queries in comment section.

8 thoughts on “Android Upload Image to Server Using Volley

  1. salman hanfi

    I want to add 6 parametrs + base 64 image string hopw can i send with this logic

    Reply
  2. karthik

    Got out of memory Error and
    E/WindowManager: Activity samplelink.imageuploadusingvolley.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41f49648 V.E….. R……D 0,0-456,144} that was originally added here.

    Could you please help me to resolve this

    Reply
  3. fandy

    And what if i want to upload file other than image ? (pdf,doc,excel dll) is this code work ?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *