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.

32 thoughts on “Android Upload Image to Server Using Volley”

  1. 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

  2. hi Neeraj,
    your code working but it throw error time of img upload

    “Some error occurred -> com.android.volley.ServerError”

    can you help me how it can solve

  3. Shravan Manerikar

    getting timeout exception , rest code is same but only difference is i’m passing the image and some other data in json format as shown below

    protected Map getParams() throws AuthFailureError {
    Map params = new HashMap();
    params.put(“PartDetails”, json);

    return params;
    }

    if i send it without selecting the image it works fine, but if i select an image then it throws timeout exception, but the entry gets uploaded in the database

  4. hey bro
    i need a help. In my application i’m getting human signature . after that signature converted into image file on local memory. Then next i want to upload those image file by choose that images manually i ‘m want do those task . if there is any possibilities to directly upload those images into my database .

  5. i want to upload image to server in android ,i use ‘com.theartofdev.edmodo:android-image-cropper:2.5.+’ library for cropping if i crop full image then upload it ,it give ” com.android.volley.ServerError “, and if crop it small size and upload then it upload succesfully.

    please suggest some solution

  6. @RequestMapping(value=”/documentUpload”,method=RequestMethod.POST)
    public ResponseEntity documentUpload(HttpServletRequest request,HttpServletResponse response) throws Exception
    {
    String image= request.getParameter(“image”);
    }
    String image is returning null in spring mvc!!!

  7. Bro i am facing com.android.volley.clienterror in a specific one server please help
    here is my code
    @Override
    protected Map getParams() throws AuthFailureError {
    Map params = new HashMap();
    params.put(“url”, imageString);
    params.put(“name”, name.getText().toString());
    return params;
    }
    };

Leave a Comment

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