Olá,
Estou tentando passar uma imagem de um celular para um servlet (para postar ele num site).
Mas os bytes não chegam. Abaixo o código.
[code]
public void publicar(String nome) {
Thread th = new Thread(new Runnable() {
public void run() {
try {
String url = "http://localhost:8084/ServidorCamera/PostarImagem";
HttpConnection con = (HttpConnection) Connector.open(url);
// Set the request method and headers
con.setRequestMethod(HttpConnection.POST);
con.setRequestProperty("If-Modified-Since",
"29 Oct 1999 19:43:31 GMT");
con.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
con.setRequestProperty("Content-Language", "en-US");
// Getting the output stream may flush the headers
OutputStream os = con.openOutputStream();
System.out.println("imgPNG env: "+getImgPNG().length); //imprime >0
os.write(getImgPNG());
os.flush();// Optional, getResponseCode will flush
// Getting the response code will open the connection,
// send the request, and read the HTTP response headers.
// The headers are stored until requested.
int status = -1;
status = con.getResponseCode();
if (status != HttpConnection.HTTP_OK) {
return;
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
th.start();
}[/code]
[code]
InputStream in = request.getInputStream();
int max = in.available();
System.out.println(“MAX:”+max); //imprime 0
byte[] foto = new byte[max];
in.read(foto);
ImagemDAO.setImagem("Nome da foto", foto);[/code]
Será que alguém sabe onde estou errando?