0

I need to upload an images one by one to the server, when image upload to the server the server performing "Image Processing", when the image processing done the server return answer. Client(android) gets the answer from the server and it needs to launch another picture immediately. And so. And so. All this should be the maximum speed

Currently: My upload speed is avg 230kB/s .

The image size on server is 362KB

The image processing in server is disabled.

the android code:

ByteArrayOutputStream bos_output = new ByteArrayOutputStream();
boolean isCompress = bmp.compress(CompressFormat.JPEG , 60, bos_output);
byte[] bos = bos_output.toByteArray();
// call the method in Thread
String response = myPost(SERVER_URL, "file_name", bos);

// the uploading method
public String myPost(String serverPath, String fileNameonserver, byte[] baos) 
{
    String fileName = fileNameonserver+".jpg";
    HttpURLConnection conn = null;
    DataOutputStream dos = null;  
    String lineEnd = "\r\n";
    String twoHyphens = "--";
    String boundary = "*****";
    try {
        URL url = new URL(serverPath);
        conn = (HttpURLConnection) url.openConnection();
        conn.setDoInput(true); 
        conn.setDoOutput(true); 
        conn.setUseCaches(false); 
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.setRequestProperty("Cache-Control", "no-cache");
        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
        conn.setRequestProperty("uploaded_file", fileName); 
        dos = new DataOutputStream(conn.getOutputStream());
        dos.writeBytes(twoHyphens + boundary + lineEnd); 
        dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\"" + fileName + "\"" + lineEnd);
        dos.writeBytes(lineEnd);
        dos.write(baos);
        dos.flush();
        dos.close();
        String response= "";
        //start listening to the stream
        Scanner inStream = new Scanner(conn.getInputStream());
        //process the stream and store it in StringBuilder
        while(inStream.hasNextLine())
            response+=(inStream.nextLine());

        return response;
    } 
    catch (Exception e)
    {
        e.printStackTrace();
        return "";
    }
}

the php code:

<?php
    $file_path = "images/";
    $file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) 
    {

        //$data = $_FILES['uploaded_file']['name'];
        //exec("ALGO.exe {$data}",$output);
        //foreach($output as $line)
        //{
        //  echo $line;
        //}
        //echo "";
        echo "success";
        //unlink($file_path);
    } else{
        echo "fail";
    }
 ?>

this code is working and i can upload images in avg of 2 second for image.

It is not good enough, it is kind a problematic to dvide the picture or scaling.

1 - I have an idea to pass only the changes but i dont have time to somthing so complicated, libraries suggestions ?

2 - Or can i use RTSP‏ ?

3 - Any strong compression fit here? ( snippet code will be excellent)

Thanks.

1 Answers1

0

Do you really need the full size image ?

Even by compressing to jpg/60, if your image is 3000x2500px directly out of the camera, this is a huge image. Are you going to use that large image for something ?

If not you could downscale the image to a more reasonable size, say 1200x900px which would greatly diminish the size once compress as a jpeg/60.

Downscaling : https://stackoverflow.com/a/17773344/578746

Community
  • 1
  • 1
Yahel
  • 8,522
  • 2
  • 24
  • 32
  • Thanks for your answer,but it is kind a problematic to dvide the picture or scaling. because the processing in the server all the picture is needed. – user3195445 Jan 17 '14 at 12:02
  • Update your question with the specifics of what you are going to do on the server to the photo. Don't forget that you are on a mobile device. Short battery life, slow cpu, small display and slow mobile connection. Again are you sure you need the large size image ? Tell us more so that we can guide you better. – Yahel Jan 17 '14 at 15:09
  • the chalenge is with the upload, with the same rools that i am mentioned above, what the server do with the image is not my project, all that i need to do is to upload the images fast, all i know that server need to find somthing in the image . – user3195445 Jan 17 '14 at 19:02