How to get an image of the save screen in the project folder and save the path in Mysql database?

0

So, I have a jsp with form, it converts the image to b64 and sends as a pro servlet string the servlet converts to b643

String stt = request.getParameter("base64img");
        try{
            String parts[] = stt.split(",");
            String imgPart = parts[1];
        BufferedImage image = null;
        byte[] imageByte;
        BASE64Decoder decoder = new BASE64Decoder();
        imageByte = decoder.decodeBuffer(imgPart);
        ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
        image = ImageIO.read(bis);
        bis.close();
        // write the image to a file
        File outputfile = new File("image.png");
        ImageIO.write(image, "png", outputfile);

        }catch(Exception e){
            e.printStackTrace();
        }

And it writes the image to the project src, how do I retrieve this path to insert into the database ??

    
asked by anonymous 04.12.2016 / 16:28

1 answer

1

Hello, use the getAbsolutePath () method.

For example:

String diretorio = outputfile.getAbsolutePath();
    
04.12.2016 / 16:40