Conversion error in the imageframe component of Primefaces

0

I'm trying to crop an image with the imageCropper component of Primefaces, but in the implementations I've done it only gives conversion error, and when not, the croppedImage object that Primefaces implements comes null. Note: The context of my web application is https. In my tests when I put any image of the web of context https it also gives error. I already put converter and everything, but the converter does not call! Please, I need help!

Here is a snippet of the page code:

<div class="Container100 Responsive100 ContainerIndent">
                    <p:fileUpload auto="true" fileUploadListener="#{fileUploadController.uploadBase64}"
                                  sizeLimit="1000000" fileLimitMessage="Atenção! Por favor, Anexe apenas uma foto!"
                                  multiple="false"
                                  label="Selecione uma foto"
                                  allowTypes="/(\.|\/)(jpg|jpeg|png)$/"
                                  update="imagemDeCorte2"/>
                </div>

                <h:panelGrid columns="2">
                    <p:imageCropper id="imagemDeCorte2" value="#{fileUploadController.croppedImage}"
                                    image="#{fileUploadController.nomeImagemB64}"
                                    rendered="#{fileUploadController.nomeImagemB64}"
                                    initialCoords="0,0,354,472"
                                    aspectRatio="0.75"/>
                </h:panelGrid>

                <p:commandButton value="Crop" action="#{fileUploadController.crop}"
                                 icon="ui-icon-scissors"/>

Java code:

 public void uploadBase64(FileUploadEvent event) throws IOException {

    arquivoFoto = event.getFile();

    String mimeType = FileUtils.detectMimeType(arquivoFoto.getContents());

    if (!arquivoFoto.getContentType().equals(mimeType)) {
        throw new IOException("Tipo do arquivo está errado: " + mimeType);
    }

    formatoFoto = arquivoFoto.getContentType();
    nomeFoto = arquivoFoto.getFileName();
    imageAsByteFoto = ByteBuffer.allocate(new Long(arquivoFoto.getSize()).intValue());

    try {
        InputStream is = arquivoFoto.getInputstream();

        //redimensiona a imagem
        BufferedImage img = ImageIO.read(is);
        BufferedImage scaledImg = Scalr.resize(img, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.FIT_TO_HEIGHT, 450, 600);

        arquivoFoto.getInputstream().read(imageAsByteFoto.array());
        ImagemBase64 ib4 = new ImagemBase64();

        String base64AsString = new String(Base64.encode(imageAsByteFoto.array()));
        ib4.setB64(base64AsString);
        ib4.setFormato(formatoFoto);
        ib4.setNome(nomeFoto);

        nomeImagemB64 = ib4.getSrc();
        nomeImagemB642 = ib4.getSrc();

        imagemFile = new File("imagemCortada.".concat(FilenameUtils.getExtension(nomeFoto)));
        org.apache.commons.io.FileUtils.writeByteArrayToFile(imagemFile, imageAsByteFoto.array());

        imagemCarregada = Base64.decode(ib4.getSrc());

        reload();

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


}
    
asked by anonymous 19.12.2016 / 12:42

0 answers