RestEasy-上载西里尔字母的文件(多部分/表单数据) [英] RestEasy - upload file (multipart/form-data) with cyrillic name

查看:93
本文介绍了RestEasy-上载西里尔字母的文件(多部分/表单数据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将文件上传到服务器时,一切都很好.但是,如果文件名包含西里尔字符,则在服务器上,该文件名会带有问号.

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.

我知道,如果您在发出请求时未在标头中放置任何字符编码,则RestEasy放置的默认字符编码为us-ascii.我尝试了几种更改方法:

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:

  • 使用新的String(filename.getBytes("US-ASCII"),"UTF-8")-无效;
  • 我编写了ContainerRequestFilter,在其中我更改了此请求的ContentType,并向ContentType添加了charset = UTF-8.设置正确,但仍然无法正常工作.

请您帮忙!我将非常感谢!

Could you please help! I would be very thankful!

谢谢!

也发布在jboss.org 论坛

Also posted on jboss.org forum

推荐答案

不要更改Content-Type,而是使用ContainerRequestFilter覆盖默认字符集属性:

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.

这篇关于RestEasy-上载西里尔字母的文件(多部分/表单数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆