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.