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]

android_upload_clientandroid_upload_server

Uploading Images with Java

Download the latest HttpClient 4.3.4 from Apache Software Foundation.

Add following jar files:

java_upload_libs

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)
                .build();

        httppost.setEntity(reqEntity);

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