This topic is the discussion thread for the Vaadin documentation page Handling file uploads in the Upload component | Vaadin.
Questions, feedback, and comments are welcome here.
This topic is the discussion thread for the Vaadin documentation page Handling file uploads in the Upload component | Vaadin.
Questions, feedback, and comments are welcome here.
Show example backend endpoint for /api/upload-handler please.
@PostMapping(value = "/fileupload/recieve", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Object> recieveFile(MultipartHttpServletRequest request,
@RequestParam("file") MultipartFile file)
throws IOException {
file.getInputStream().readAllBytes();
return new ResponseEntity<>(HttpStatus.OK);
}
What is the benefit of the InMemoryUploadHandler or FileUploadHandler compared to basic UploadHandler? If I'm not missing something, with modern Java API I think all those are equally simple with the simple lambda expression, but there would be less concepts for user to understand, use cases would be implemented in almost equal manner and API would be more like in other frameworks. Thus, I'd like to at leas not call that "an advanced use case", but maybe even make that the default approach for all show use cases.
For example if I really need to cache the whole file contents to a byte[] like in the InMemoryUploadHandler, I could do that like this:
Upload upload = new Upload(uploadEvent -> {
// these three lines to make this similar to InMemoryUploadHandler
String fileName = uploadEvent.getFileName();
String contentType = uploadEvent.getContentType();
long fileSize = uploadEvent.getFileSize();
// Now this is all I see InMemoryUploadHandler doing for me
byte data = uploadEvent.getInputStream().readAllBytes();
// Do something with the file data…
// processFile(data, fileName);
});