工作,我有一個形象在我的豆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