In my Vue App I have this file input:
<input type="file" multiple @input="handleFileInput" />
The selected files are passed to my this upload method:
public async uploadFiles(file: File) {
[...]
const formData = new FormData();
formData.append('fileName', file.name);
formData.append('file', file);
[...]
await axios.post('my-upload-url', formData);
}
The js log before sending it:
The network log after sending it:
My Resteasy controller answers:
@POST
@Transactional
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadMultipartData(@MultipartForm @Valid MyDto dto) {
// dto.file -> my file
}
The DTO:
public class MyDto {
@NotNull
@FormParam("file")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public InputStream file;
}
When transferring other file types (pdf, png, jpg, mp3, ...) the file is in the InputStream of the DTO as expected. However, when it the file is an .eml file, the InputStream is null.
Update: when renaming the file from text.eml to test.txt, the upload works.
Why?
In other words, how do I consume a File with a content type of message/rfc822 in my REST Api? Do I need a separate method that accepts this specific Media Type?
@PartType(MediaType.APPLICATION_OCTET_STREAM)
and then give something that's not an octet stream. Mime type should reflect what you are actually uploading. – Tupungato