0

i'm using jsf 2.2 primefaces 6.0 and i implemented a solution to download pictures.The issue is that the solution works fine when i put the images on ressource file internally like that:enter image description here

but when i try to download it from an external repository using a link then an error message appears :enter image description here

Here the xhtml code:

<p:column style="text-align: center" headerText="Télécharger">
                        <p:commandButton value="Download" ajax="false"
                            onclick="PrimeFaces.monitorDownload(start, stop);"
                            icon="ui-icon-arrowthick-1-s">
                            <p:fileDownload value="#{fileDownloadView.file}" />
                        <f:setPropertyActionListener value="#{a}"
                            target="#{demandeBean.demandeSelectionnee}" />
                    </p:commandButton>
                </p:column>

Here the java Bean code:

package mBeans;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

@ManagedBean
@SessionScoped
public class FileDownloadView implements Serializable{

    private StreamedContent file;

    public FileDownloadView() throws FileNotFoundException, TransformerConfigurationException, TransformerException {
        InputStream stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(
                "http://localhost:18080/openCars/images/hichem.jpg");
        file = new DefaultStreamedContent(stream, "image/jpg", "downloaded_optimus.jpg");

    }

    public StreamedContent getFile() {
        return file;
    }

} I need help to solve the problem.

0 Answers0