Take a Photo from Android Camera and Upload it to a Remote PHP Server

In this tutorial, I’d like to share how to write a simple Android application to take a picture, as well as upload the image to a remote PHP server. Let’s get started with a simple Java application.

[caption id=”attachment_3447” align=”aligncenter” width=”600”]Dynamsoft Barcode Reader SDK Ads Powered by Dynamsoft[/caption]


Uploading Images with Java

Download the latest HttpClient 4.3.4 from Apache Software Foundation.

Add following jar files:


Learn the sample code and make your own application:

``` public static void main(String[] args) throws Exception { // TODO Auto-generated method stub CloseableHttpClient httpclient = HttpClients.createDefault(); try { HttpPost httppost = new HttpPost(“http://localhost:8003/savetofile.php”); // your server

        FileBody bin = new FileBody(new File("my.jpg")); // image for uploading

        HttpEntity reqEntity = MultipartEntityBuilder.create()
                .addPart("myFile", bin)


        System.out.println("executing request " + httppost.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httppost);
        try {