0
I have a project in JSF
put.
One of the parts is to add the image to the product by making the upload
of the image.
That’s why I’m using the primefaces p:fileUpload
, it works, but the image is "played" to the PC folder and not to the project folder, I need this image to go to the folder inside the project, in WebContent-Images
.
Upload method:
public void upload(FileUploadEvent event) {
UploadedFile uploadedFile = event.getFile();
try {
File file = new File("", uploadedFile.getFileName());
OutputStream out = new FileOutputStream(file);
out.write(uploadedFile.getContents());
out.close();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("Upload completo", "O arquivo " + uploadedFile.getFileName() + " foi salvo!"));
} catch (IOException e) {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_WARN, "Erro", e.getMessage()));
}
}
blz, thank you for your attention.
– user140439