RestEasy - upload file (multipart/form-data) with cyrillic name

…衆ロ難τιáo~ 提交于 2019-12-25 01:52:45

问题


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:


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.



来源:https://stackoverflow.com/questions/27986897/resteasy-upload-file-multipart-form-data-with-cyrillic-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!