2014-04-15 27 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

回答

相关问题