Commit 1163ed10 authored by michael.simon's avatar michael.simon
Browse files

Primefaces problem for upload with file.getContent(). Not working. Now

implemented with file.getInputStream() which is working.
parent e67dc615
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
******************************************************************************/ ******************************************************************************/
package edu.kit.scc.webreg.bean.admin; package edu.kit.scc.webreg.bean.admin;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
...@@ -20,6 +21,7 @@ import javax.faces.context.FacesContext; ...@@ -20,6 +21,7 @@ import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent; import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.commons.io.IOUtils;
import org.primefaces.event.FileUploadEvent; import org.primefaces.event.FileUploadEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -93,18 +95,24 @@ public class ImageGalleryBean implements Serializable { ...@@ -93,18 +95,24 @@ public class ImageGalleryBean implements Serializable {
public void handleFileUpload(FileUploadEvent event) { public void handleFileUpload(FileUploadEvent event) {
logger.debug("A file was uploaded: {}", event.getFile().getFileName()); logger.debug("A file was uploaded: {}", event.getFile().getFileName());
ImageEntity image = imageService.createNew(); try {
image.setImageData(new ImageDataEntity()); ImageEntity image = imageService.createNew();
image.setImageData(new ImageDataEntity());
image.setName(event.getFile().getFileName());
image.setImageType(ImageType.PNG); image.setName(event.getFile().getFileName());
image.getImageData().setData(event.getFile().getContents()); image.setImageType(ImageType.PNG);
imageService.save(image); image.getImageData().setData(IOUtils.toByteArray(event.getFile().getInputstream()));
imageService.save(image);
imageList = imageService.findAll();
imageList = imageService.findAll();
FacesMessage msg = new FacesMessage("Hochgeladen", event.getFile().getFileName()); FacesMessage msg = new FacesMessage("Hochgeladen", event.getFile().getFileName());
FacesContext.getCurrentInstance().addMessage("messageBox", msg); FacesContext.getCurrentInstance().addMessage("messageBox", msg);
} catch (IOException e) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Bild Daten fehlen", e.getMessage());
FacesContext.getCurrentInstance().addMessage("messageBox", msg);
logger.warn("Exception while upload of image", e);
}
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment