自定义上传组件

时间:2013-11-12 16:51:35

标签: java vaadin

我正在使用vaadin开发我的第一个应用程序。现在我正在尝试自定义上传组件。总之,我必须上传图像。

现在我的组件以标准方式实现:

public OutputStream receiveUpload(String filename,String mimeType) {
// Create upload stream
FileOutputStream fos = null; // Stream to write to
try {
    // Open the file for writing.
    file = new File("/tmp/uploads/" + filename);
    fos = new FileOutputStream(file);
} catch (final java.io.FileNotFoundException e) {
    new Notification("Could not open file<br/>",e.getMessage(),Notification.Type.ERROR_MESSAGE).show(Page.getCurrent());
    return null;
}
return fos; // Return the output stream to write to
 }

我想问你,如果我可以在不使用服务器上的临时文件的情况下上传文件。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

当然,

您只需要为上传组件提供OutputStream。 例如,这可能是一个ByteArrayOutputStream,因此您将所有内容都作为一个大型bytearray。

请注意,当用户上传10 GB大小的文件时,您还需要在服务器上为该请求提供那么多内存

安德烈

相关问题