2014-04-15 28 views
0

請讓我知道如何使用primeface fileUpload.i上傳圖像要將上傳的圖像存儲到文件夾中並且還想使用縮略圖來調整圖像大小。已經嘗試了primeface文件上傳但沒有得到。使用primefaces上傳圖像並使用縮略圖來調整它的大小

<p:fileUpload allowTypes="/(\.|\/)(gif|jpe?g|png)$/" auto="true" dragDropSupport="true" fileUploadListener="#{loginController.fileUploadHandler}" />

public void fileUploadHandler(FileUploadEvent event) throws IOException { 
    UploadedFile file = event.getFile(); 
    InputStream inStream = file.getInputstream(); 
    Os.write("C:\\Users\\think again\\Desktop\\uploaded\\pic.jpg", inStream); 
    Thumbnails.of(new File("C:\\Users\\think again\\Desktop\\uploaded").getAbsoluteFile()).size(100, 100).outputFormat("jpg").toFile("C:\\Users\\think again\\Desktop\\thumb"); 
} 

但該文件對象包含部分項目不知道它是什麼。將得到part.please內的FileItem對象幫我將圖片上傳到correspondding位置

+0

嘗試http://stackoverflow.com/questions/8875818/how-to-use-primefaces-pfileupload-listener-method-is-never-invoked?rq=1 –

+0

@EvesMary:我的支持bean是會話作用域。而不是顯示上傳的消息,我需要將圖像存儲到文件中 – Ansar

回答

相關問題