RestEasy - upload file (multipart/form-data

2019-08-29 09:07发布

When I upload a file to the server, everything is fine. But if the name of the file contains cyrillic characters, on the server that filename appears with question marks.

I don't set any character encoding when I send request to the server.

I know that if you don't put any character encoding in the header when you make request, the default character encoding that RestEasy puts is us-ascii. I tried a couple of ways to change it:

  • With new String(filename.getBytes("US-ASCII"), "UTF-8") - didn't work;
  • I wrote ContainerRequestFilter, where I changed the ContentType of this request and I added charset=UTF-8 to the ContentType. It is set correctly but still doesn't work.

Could you please help! I would be very thankful!

Thanks!

Also posted on jboss.org forum

1条回答
欢心
2楼-- · 2019-08-29 09:45

Don't change the Content-Type but use a ContainerRequestFilter to overwrite the default charset property:

@Provider
public class CharsetFilter implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
         requestContext.setProperty(InputPart.DEFAULT_CHARSET_PROPERTY, "UTF-8");
    }

}

Maybe you should check if there is a encoding provided and overwrite only if not.

查看更多
登录 后发表回答