Hello Developer,
i am a newcomer at vaadin and have a question about uploads?
I build two variants to upload files. One Html5 Drag&Drop Box and a traditional upload field.
Currently i load all files in a buffer and show them at the screen.
But where is the file saved at this moment? It is in the browser cache? On my files system and i didn’t know it? Or handle vaadin this things by him self?
I want to save this files on my file system, if the user clicks save and not earlier.
The files that are uploaded with the Vaadin Upload component are not stored anywhere by default; the content is provided to the listener class as a stream of bytes. Any operation after this must be implemented by the user (such as storing the file to the file system).
So, to achieve the functionality you want, you need to keep the content in memory until the user clicks the ‘save’ button; for instance a field in your view class. Then simply add a listener to your button that creates a File object, writes the content to it, and your done. Remember to close any streams and empty any temporary fields after you are done, to conserve memory on the server.
If the content can be very big or you will have many concurrent users, it might make sense to store the data directly in a temporary file and then copy/move the file if the user clicks “Save”. You can use File.createTempFile(…) and File.deleteOnExit() - google for javadoc and examples.