I'm using the Nokia Series 60 emulator and MMAPI to capture and image and send it to a server via HTTP. Can this be done using HTTP POST or is there another way to get the image to a server via HTTP? If someone has done this before, could you send some sample code of what the HTTP connection properties look like and how the image bytes are sent through the output stream? On the server side I am trying to use PHP to display the png image sent from the phone on a web page. Any help is greatly appreciated!
Michael Yuan
author
Ranch Hand
Joined: Mar 07, 2002
Posts: 1427
posted
0
Yes, you can. No special connection property is needed. I just write the entire byte array to the stream and then readFully() from the servlet. The server then saves it a local file with an appropriate extension (according to you capturing options). But I do not know to do it with PHP servers. If you know, please post back. On the client side:
On the server side
[ March 21, 2004: Message edited by: Michael Yuan ]
Thanks for your reply Michael. We originally tried using the code in your reply but this didn't seem to work with PHP. We just found that the following solution works when receiving the image with a PHP page. client side:
PHP server side:
In the above example "bytes" is the name of the POST variable and the content-type must be "multipart/form-data". The "boundary" string is also needed for "multipart/form-data" transfers. The PHP code creates a file from the "bytes" POST variable called 'testDATE.png' where DATE is the time the file was created. Regards, Greg
Michael Yuan
author
Ranch Hand
Joined: Mar 07, 2002
Posts: 1427
posted
0
Great. Thanks for the tip! When I think about it, you can use Base64 to encode byte arrays to ASCII strings on both ends of the communication as well. cheers Michael
leena bhegde
Greenhorn
Joined: Mar 15, 2009
Posts: 2
posted
0
The third post given shows example that it is correct i tried the same example...but its not sending anything to server.
This message was edited 1 time. Last update was at by leena bhegde
leena bhegde
Greenhorn
Joined: Mar 15, 2009
Posts: 2
posted
0
The third post given shows example that it is correct i tried the same example...but its not sending anything to server.
Please reply as soon as possible
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------4664151417711");
// might not need to specify the content-length when sending chunked data.
conn.setRequestProperty("Content-Length", String.valueOf((message1.length() + message2.length() + imgData.length)));
System.out.println("open os");
os = conn.getOutputStream();