Upload image from J2ME client to a Servlet
Posted
by Akash
on Stack Overflow
See other posts from Stack Overflow
or by Akash
Published on 2010-05-15T06:48:55Z
Indexed on
2010/05/15
16:44 UTC
Read the original article
Hit count: 480
I want to send an image from a J2ME client to a Servlet.
I am able to get a byte array of the image and send it using HTTP POST.
conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
os.write(bytes, 0, bytes.length); // bytes = byte array of image
This is the Servlet code:
String line;
BufferedReader r1 = new BufferedReader(new InputStreamReader(in));
while ((line = r1.readLine()) != null) {
System.out.println("line=" + line);
buf.append(line);
}
String s = buf.toString();
byte[] img_byte = s.getBytes();
But the problem I found is, when I send bytes from the J2ME client, some bytes are lost. Their values are 0A
and 0D
hex. Exactly, the Carriage Return and Line Feed.
Thus, either POST method or readLine()
are not able to accept 0A
and 0D
values.
Any one have any idea how to do this, or how to use any another method?
© Stack Overflow or respective owner