4

I have an idea for an app and am currently learning Android development. I'm fairly familiar with creating simple standalone apps.

I'm also familiar with PHP and webhosting.

What I want to do is, make an android app send an image to a server via the internet and make the server return a processed image. I have no clue how I'd do that.

Can you please tell me how can I go about achieving this or which topics should I look into? Also, what scripts can I use to do the processing on the web server? Particularly, can I use PHP or Java?

Thanks!

GrowinMan
  • 4,891
  • 12
  • 41
  • 58

3 Answers3

6
For Image Uploading
///Method Communicate with webservice an return Yes if Image uploaded else NO
String  executeMultipartPost(Bitmap bm,String image_name) {
    String resp = null;
    try {  
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bm.compress(CompressFormat.JPEG, 75, bos);
        byte[] data = bos.toByteArray();
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost postRequest = new HttpPost("domain.com/upload_image.php");
        ByteArrayBody bab = new ByteArrayBody(data, image_name);

        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        reqEntity.addPart("uploaded", bab);
        reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
        postRequest.setEntity(reqEntity);
        HttpResponse response = httpClient.execute(postRequest);
        BufferedReader reader = new BufferedReader(new  InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String sResponse;
        StringBuilder s = new StringBuilder();
        while ((sResponse = reader.readLine()) != null) {
            s = s.append(sResponse);
        }
        resp=s.toString();
    } catch (Exception e) {
        // handle exception here
        Log.e(e.getClass().getName(), e.getMessage());
    }
    return resp;
}

//PHP Code 
<?php 

    $target = "upload/"; 

    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok=1; 
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
    {
        echo "yes";
    } 
    else {
        echo "no";
    }
?> 
Triode
  • 11,309
  • 2
  • 38
  • 48
Munish Kapoor
  • 3,141
  • 2
  • 26
  • 41
1

Normally we do it with http connection, you can pass the image in the post params, for further reference please see the link

Community
  • 1
  • 1
Triode
  • 11,309
  • 2
  • 38
  • 48
0

You have to create a simple php web service which accepts parameter as image bytes and which process the image and store in server. For this android app will send image data in bytes to the server using HttpPost.

For retrieving purpose you have to create a other web service which will output the file name of image from where android app can retrieve the image

Maneesh
  • 6,098
  • 5
  • 36
  • 55