Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
file uploader
hi guys,
I'm new to spring and I'm trying to build a small application to allow file upload.
Basically you should be able to upload a file from the computer file system and display the content of the file inside a textarea, and I was wondering if anybody can give me a few suggestions and guide me through the process please
i've found some suggestions here and there, even on the vaadin book but i'm still a bit unsure.
So, I've started a Maven project and this is what I have so far:
public class MyUI extends UI implements Receiver, SucceededListener{
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
TextArea fileArea = new TextArea("File information");
fileArea.setRows(20);
fileArea.setWidth("350px");
final TextField name = new TextField();
name.setCaption("Load the file here:");
layout.addComponents( label, name, button, fileArea);
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
}
MyUI receiver = new MyUI();
Upload upload = new Upload("Upload File Here", receiver);
}
So, my main class implements Receiver and SucceedeListener interfaces to implement the upload functionality.
I created an upload object called upload and now I presume it's just a matter of writing the uploadSucceeded(Upload.SucceededEvent event) that is required, but how would I handle the file stream?
thanks
I assume you've already looked at the tutorial for Upload?
In any case you need to implement the Receiver.receiveUpload method. The purpose of this method - and this is not very clear from the Javadoc - is to let Vaadin know where you want the uploaded content to go. Vaadin will write the uploaded file to the outputstream which is the result of said method. So basically you don't really handle the stream yourself. Typically this outputstream will be a FileOutputStream but that is up to you. Vaadin will automatically close this outputstream once the upload is completed so you need not be concerned with closing.
Peter