J2ME passa imagem para Servlet

1 resposta
BooooH

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.

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();
    }
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);

Será que alguém sabe onde estou errando?

1 Resposta

BooooH

POr favor pessoal, dêem uma ajuda aí que já estou entrando em parafuso…

:?

Criado 9 de dezembro de 2008
Ultima resposta 9 de dez. de 2008
Respostas 1
Participantes 1