Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
How to consume File with a content type of message/rfc822 in my REST API in a MultipartFormData?

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:

enter image description here

The network log after sending it:

enter image description here

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So this most certainly has to do with how your server handles the uploaded file. application/octet-stream simply represents a generic/unknown binary file. From RFC 2046 § 4.5.1:

The "octet-stream" subtype is used to indicate that a body contains arbitrary binary data.

Most apps will try to determine the file mimetype by looking at their file's extension, but it will have trouble determine it if the extension is unknown to them. An eml file is just a text file, which explains why when changing the extension to txt works without problems. The easiest way to verify this by taking a simple txt file and changing its extension to unknown (for example) and try to upload that file.

I have set up an example replicating the exact same scenario and in this case the server has no trouble reading the file contents.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!