Erro ao salvar imagem da servlet em servidor linux

29/04/2020

0

Boa tarde amigos,
Sou novo no fórum e não estaria pedindo ajuda se eu já não tivesse vasculhado de todas as formas a internet.

Estou desenvolvendo um site onde o usuário pode subir uma imagem e recortá-la, recebo ela no Servlet em base64, faço a conversão para BufferedImage e gravo em uma pasta.
No windows ficou show, gravou perfeitamente, porém, ao subir para o servidor linux, ao executar a servlet o tomcat me retorna uma pagina de erro 500, mas sem a descrição do que é.
Se eu tirar a parte da manipulação de imagem, o código roda liso, e até gera um pdf corretamente na pasta configurada.

Comentei muita coisa que testei.

Segue meu código:

String localImagemLogotipo = request.getServletContext().getRealPath("/Logotipos").replace("\\build", "");
            String erroFoto = "";
            try {
                if (!usuario.getLogotipo().equals("")) {

                    BASE64Decoder decoder = new BASE64Decoder();
                    imageByte = decoder.decodeBuffer(usuario.getLogotipo().replace("data:image/png;base64,", ""));
                    ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
                    image = ImageIO.read(bis);
                    bis.close();

                    int width = image.getWidth();
                    int height = image.getHeight();
                    BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
                    int px[] = new int[width * height];
                    image.getRGB(0, 0, width, height, px, 0, width);
                    output.setRGB(0, 0, width, height, px, 0, width);

                    //String localImagemLogotipo = request.getServletContext().getRealPath("/Logotipos").replace("\\build", "");
                    ImageIO.write(output, "png", new File("/home/acamonplace/ea-tomcat85/webapps/Documentos/Logotipos/teste.png"));

                    //Criando documento imagem
//                Image img = Image.getInstance(localImagemLogotipo + "/" + nomeAleatorio + ".png");
                    //Image img = Image.getInstance("/home/acamonplace/ea-tomcat85/webapps/Documentos/Logotipos/teste.png");
                    //img.setAlignment(Image.ALIGN_LEFT);
                    //
                    //img.scaleAbsolute(250, 125);
                    //img.scaleAbsolute(152, 76);
                    //Adicionando imagem no documento
                    // document.add(img);
                    //lado1.addElement(img);
                }
            } catch (IOException ex) {
                request.setAttribute("erro", ex.getMessage());
                request.getRequestDispatcher("erro.jsp").forward(request, response);
            }


Minha função para converter:

 public static BufferedImage scale(BufferedImage src, int w, int h) {
        BufferedImage img
                = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        int x, y;
        int ww = src.getWidth();
        int hh = src.getHeight();
        int[] ys = new int[h];
        for (y = 0; y < h; y++) {
            ys[y] = y * hh / h;
        }
        for (x = 0; x < w; x++) {
            int newX = x * ww / w;
            for (y = 0; y < h; y++) {
                int col = src.getRGB(newX, ys[y]);
                img.setRGB(x, y, col);
            }
        }
        return img;
    }
Jonatas Teodoro

Jonatas Teodoro

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar