Today most of android application’s allow you to click image and upload to web. In this post i explain you how to create application in android which access your mobile camera, click image and upload to server. This post is very help full for those who is new to android and need to upload image to server.

Capture image and upload to server in android

Update: To upload original image to server please follow last section of this post.

Capture image from Application

Step 1. Create new android project in your Android Studio or Eclipse.

Step 2. Open your AndroidManifest.xml file where we add permission to access camera, write external storage, internet permission.

Step 3. Now open your mainactivity.xml file and add ImageView and add two button one for click image and second is to upload image o server.

Step 4. Open your MainActivity.java  file inside your package. Now when we click on button to click image we need to open default camera app by passing intent. I create method inside my class to do this.

Step 5. When image is click we need to get the image and need to display in image view so i use onActivityResult method to do this

 Step 6. Now when user click on upload button we start uploading our image to server. Before uploading image i convert  image to base 64 using base64 class and i also use httpclient-4.1-beta.jar to upload.

Upload image to server:

Note: Bellow http methods are depreciate in android latest version 6, so please follow this link where i create a complete new async task class to send or receive data.

 Step 7. I am using PHP to handle upload image and also create image from base64 encoded data.

Complete code:

Upload full size image to server android

Above code have some issue in some version of android. In some of android version it just upload thumbnail of image to server not original image, if you want to upload original then use bellow code.

Above code give you full size image/original image, you also manage the quality of image by changing it quality eg. 90, 50, etc.

🙂