Java 在vaadin中将文件保存到数据库
您好,我正在尝试使用vaadin将文件保存到我的数据库中。我有一个web应用程序,允许用户上传文件,到目前为止,文件上传到我的文件系统。以下是我的上传代码:Java 在vaadin中将文件保存到数据库,java,sql,postgresql,upload,vaadin,Java,Sql,Postgresql,Upload,Vaadin,您好,我正在尝试使用vaadin将文件保存到我的数据库中。我有一个web应用程序,允许用户上传文件,到目前为止,文件上传到我的文件系统。以下是我的上传代码: public class FileUploader implements Receiver, SucceededListener { File file; public OutputStream receiveUpload(String fileName, String mimeType) {
public class FileUploader implements Receiver, SucceededListener {
File file;
public OutputStream receiveUpload(String fileName, String mimeType) {
FileOutputStream fos = null;
try {
file = new File("C:\\Documents and Settings\\ABDEN00U\\Desktop\\tmp\\" + fileName);
fos = new FileOutputStream(file);
} catch (final java.io.FileNotFoundException e) {
new Notification("Could not open file", e.getMessage(), Notification.TYPE_ERROR_MESSAGE.ERROR_MESSAGE).show(Page.getCurrent());
return null;
}
return fos;
}
@Override
public void uploadSucceeded(SucceededEvent event) {
// TODO Auto-generated method stub
file_upload.setVisible(true);
file_upload.setSource(new FileResource(file));
}
我要做的是抓取文件并将其转换为字节数组,然后将其上载到我的postgres数据库。在
上载成功的方法中,您可以将文件
转换为字节[]
怎么会?”这是一个可能的解决办法
然后将字节[]
存储到数据库中的blob字段中