工作,我有一个形象在我的豆byte[]
。用户可以使用<h:inputFile/>
上传图片。只要用户点击上传,图像应该显示在页面中(不应保存在DB /文件夹中)。我尝试使用Base64转换,但在IE中它只显示32KB大小的图像。 以下是我的xhtml代码。
<h:form id="signatureform" enctype="multipart/form-data"> <h:inputFile id="inputFile" label="file1" value="#{bean.part}"/> <h:commandButton id="upButton" type="submit" action="#{bean.uploadSignature}" value="Upload" styleClass="commandButton"> </h:commandButton> </h:form>
<h:graphicImage url="data:image/jpg;base64,#{bean.encodedImage}" width="275px" height="75px"></h:graphicImage>
我的Java代码为
将字节数组显示为图像; BASE64数据URI不32KB以上在IE
private String encodedImage ;
private Part part;
//getters and setters
public String uploadSignature() throws IOException {
InputStream inputStream = null;
try {
inputStream = part.getInputStream();
encodedImage = new String(Base64.encode(IOUtils.toByteArray(inputStream)));
} catch (Exception e) {
} finally {
if (inputStream != null) {
inputStream.close();
}
}
return SUCCESS;
}
我与<a4j:mediaOutput/>
但没有帮助尝试。请帮我解决它。
为什么你会*不*在某处被保存呢?当然,这是他们上传的重点。 – 2015-04-02 12:42:24
是的。保存按钮将保存到数据库中。保存工作正常,只显示问题。 – 2015-04-02 12:45:02
因此,将它立即保存到数据库中*,但用一个标志来说明它未经确认 - 或将其保存在不同的表格中,或许。除此之外,这意味着当用户*单击保存时,您已经获得了数据... *和*这意味着您可以轻松地显示它。 – 2015-04-02 12:46:42