I am using Vaadin 24 with Spring Boot 3.x and Tomcat as servlet container. When I try to upload file with Vaadin component, Upload, MIME type of uploaded file is application/octet-stream
when I expect application/rar
with rar files (or any other equivalent like application/vnd.rar
or application/x-rar-compressed
). It might be also worth noting that I am using Firefox web browser on Windows OS.
I set up success listener to Upload
component like this
addSucceededListener(success -> {
val receiver = (MemoryBuffer) this.getReceiver();
val length = success.getContentLength();
val fileName = success.getFileName();
val mime = success.getMIMEType(); // mime type is application/octet-stream
...
});
Why it is application/octet-stream
and what can I change, so the MIME type is application/rar
or any other equivalent, so I can better handle the file?
Whatever you see on the server side, is what your browser sends you.
If you check the network-tab in your browser dev-tools, you will see
a request for the upload of the file (basically
http://localhost:8080/VAADIN/dynamic/resource/.../upload
).
If you inspect the payload, you will see, that this is multipart
form-data and the part for the uploaded file contains a Content-Type
and this is what Vaadin gives you for getMIMEType()
.
Neither Spring nor Vaadin changes the value. And you are well advised to not trust whatever the client is sending here.