Multi-byte characters in multipart/form-data get corrupted in RESTEasy

Solution Unverified - Updated -

Issue

  • When sending a text attachment that contains multi-byte characters (for example, Scandic characters like Euro €), we confirmed that it actually reaches the RESTEasy service. However, the text attachment is corrupted when saving it as a file.
  • The following is the source code:
@Path("/multipart")
public class MultipartService {
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response processAttachments(MultipartInput input, @Context ServletContext context) throws Exception {
        List<InputPart> parts = input.getParts ();
        for (InputPart part : parts) {
            byte[] bytes = part.getBody(byte[].class, null);
            String writeFileLocation = context.getInitParameter("write.file.location");
            FileOutputStream fileOutputStream = new FileOutputStream(new File(writeFileLocation));
            IOUtils.write(bytes, fileOutputStream);
            IOUtils.closeQuietly(fileOutputStream);
        }
        return Response.ok().build();
    }

Environment

  • JBoss Enterprise Application Platform (EAP)
    • 5.x
    • 6.x
  • JBoss Enterprise SOA Platform (SOA-P)
    • 5.x
  • JBoss RESTEasy

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.