using zuul proxy mode: @EnableZuulProxy,
upload file: 中文.txt
my service:
@RequestMapping("file")
public String file(MultipartFile file) {
log.info("file:{}", file.getOriginalFilename());//at this, is print ????.txt, not print 中文.txt. Chinese garbled
String name = "E:/" + file.getOriginalFilename();
try {
Path path = Paths.get(name);
if (Files.notExists(path)) {
Files.createFile(path);
}
output = new FileOutputStream(name);
IOUtils.copy(file.getInputStream(), output);
output.close();
} catch (Exception e) {
log.error("upload error", e);
return "error";
} finally {
IOUtils.closeQuietly(output);
}
return "ok";
}
Comment From: treeleafj
no zuul can be
Comment From: spencergibb
file upload is supported better through the zuul servlet directly rather than the spring mvc controller. Prefix your uploads with /zuul and try.
Comment From: treeleafj
using zull is correct, thanks~
Comment From: jxctx88
I have the same problem, how do I solve it
Comment From: eacdy
@jxctx88 add /zuul into your URL. REF: http://cloud.spring.io/spring-cloud-static/Dalston.SR1/#_uploading_files_through_zuul
Comment From: jxctx88
@eacdy 是springmvc过滤掉文件上传吗,通过其他方式吗,能给个实例吗,不是太明白
Comment From: treeleafj
是zuul拦截掉了, 要在zuul那配置上传的接口地址, 才会不做特殊处理
Comment From: jxctx88
是自己重写文件上传的接口,不用使用zuul的文件上传吗?
程统雄
tongxiong Cheng
软件工程师
T: 18321982804
E: tongxiong.cheng@mi-me.com
A: 上海浦东新区银山路183号6座101A
------------------ 原始邮件 ------------------ 发件人: "leaf";notifications@github.com; 发送时间: 2017年6月6日(星期二) 下午3:19 收件人: "spring-cloud/spring-cloud-netflix"spring-cloud-netflix@noreply.github.com; 抄送: "梦幻星空"351162717@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [spring-cloud/spring-cloud-netflix] zuul proxy file upload, filename is Chinese garbled (#1385)
是zuul拦截掉了, 要在zuul那配置上传的接口地址, 才会不做特殊处理
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Comment From: treeleafj
@jxctx88 刚记错了, 应该是上传文件如果通过zuul的话, 在接口地址前面加上zull, 如果你是file/upload, 那么就要在页面使用时, zull/file/upload
Comment From: jxctx88
还是不可以,应该是添加zuul吧
程统雄
tongxiong Cheng
软件工程师
T: 18321982804
E: tongxiong.cheng@mi-me.com
A: 上海浦东新区银山路183号6座101A
------------------ 原始邮件 ------------------ 发件人: "leaf";notifications@github.com; 发送时间: 2017年6月6日(星期二) 下午3:28 收件人: "spring-cloud/spring-cloud-netflix"spring-cloud-netflix@noreply.github.com; 抄送: "梦幻星空"351162717@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [spring-cloud/spring-cloud-netflix] zuul proxy file upload, filename is Chinese garbled (#1385)
@jxctx88 刚记错了, 应该是上传文件如果通过zuul的话, 在接口地址前面加上zull, 如果你是file/upload, 那么就要在页面使用时, zull/file/upload
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Comment From: jxctx88
@treeleafj 你说的意思是什么都不用改变,就请求的URL添加zuul就可以了,还是说我们过滤文件上传的URL,重写文件上传的接口,不要通过zuul走文件上传
Comment From: eacdy
@jxctx88 是的 不用变 加个/zuul前缀就可以了。
Comment From: treeleafj
是直接URL前面加zuul, 前提是你的zuul是采用@EnableZuulProxy启动的:
Comment From: eacdy
@jxctx88 I write two samples below. 1. file upload microservice: https://github.com/itmuch/spring-cloud-docker-microservice-book-code/tree/master/microservice-file-upload 2. Zuul file upload sample: https://github.com/itmuch/spring-cloud-docker-microservice-book-code/tree/master/microservice-gateway-zuul-file-upload Testing with file size up to 2G, even Chinese filename is OK. Hope helps. === 考虑到老外也可能跑到帖子里提问,还是用英文回复一下吧。
Comment From: jxctx88
@treeleafj @eacdy This problem has been resolved,Thank you very much.
exampl: url:http://localhost:8080/test/simple/upload http://localhost:8080/zuul/test/simple/upload
Comment From: luckanna
Although with /zuul you can,However, zuul will regenerate the sessionid, resulting in the loss of session, I don't know how to solve the problem
Comment From: ghost
我也遇到这个问题了,解决办法就是在前端请求url前加上一个zuul,最后问题完美解决!
Comment From: lei911gang
zuul upload big file timeout ,how to solve。zuul大文件上传超时怎么解决
Comment From: eacdy
@lei911gang Add these below in zuul:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
ribbon:
ConnectTimeout: 3000
ReadTimeout: 60000
If you are using Edgware.RELEASE, There is a bug: https://github.com/spring-cloud/spring-cloud-netflix/issues/2570
Comment From: lei911gang
your reply solved my problem,a lot thanks
------------------ 原始邮件 ------------------ 发件人: "周立";notifications@github.com; 发送时间: 2017年12月22日(星期五) 晚上6:30 收件人: "spring-cloud/spring-cloud-netflix"spring-cloud-netflix@noreply.github.com; 抄送: "Rlserim-FTD"89172572@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [spring-cloud/spring-cloud-netflix] zuul proxy file upload, filename is Chinese garbled (#1385)
@lei911gang Add these below in zuul: hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 ribbon: ConnectTimeout: 3000 ReadTimeout: 60000
If you are using Edgware.RELEASE, There is a bug: #2570
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Comment From: say1or
额。大佬们 我url直接加 /zuul前缀貌似不行啊 怎么报404了
Comment From: colinzhy
Yes, by prefix a /zuul on the url, the messy code issue can be fixed.
My approach is to change the configuration zuul.servletPath=/, it works too. but it will cause another issue, that is the health API (actuator) will never work, any solution on this? I am using spring boot 1.5.18.RELEASE.
Comment From: liujingkun2017
1、加上/zuul; 2、自己重写内部实现
Comment From: Boonearbear
我也遇到了这个问题 我在我的上传文件的时候加上zull 也是返回的一个????.doc 看了源码解答说需要重新注入@Bean FormBodyWrapperFilter(new FormHttpMessageConverter),然后实现setCharset,但是还是一样返回 我贴上代码 `package xin.iot.filter;
import java.io.UnsupportedEncodingException; import java.nio.charset.Charset;
import org.springframework.core.io.Resource; import org.springframework.http.converter.FormHttpMessageConverter;
public class MyFormHttpMessageConverter extends FormHttpMessageConverter{
public MyFormHttpMessageConverter() {
System.out.println("init orther FormHttpMessageConverter ===================");
setCharset(Charset.forName("UTF-8"));
setMultipartCharset(Charset.forName("UTF-8"));
}
@Override
public void setCharset(Charset charset) {
this.setCharset(Charset.forName("UTF-8"));
}
@Override
protected String getFilename(Object part) {
if (part instanceof Resource) {
Resource resource = (Resource) part;
String filename = resource.getFilename();
if (filename != null && super.DEFAULT_CHARSET != null) {
try {
System.out.println("init orther ovveride getfilename ==================="+"old name:"+filename );
filename = new String(filename.getBytes(),"UTF-8").toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return filename;
}
else {
return null;
}
}
} `
下面是注入: @SpringBootConfiguration public class BeanFilter {
@Bean
PreFilter preFilter() {
return new PreFilter();
}
@Bean
PostFilter postFilter() {
return new PostFilter();
}
@Bean
ErrorFilter errorFilter() {
return new ErrorFilter();
}
@Bean
FormBodyWrapperFilter formBodyWrapperFilter() {
return new FormBodyWrapperFilter(new MyFormHttpMessageConverter());
}
}
请问我怎么解决这个问题 头疼,上传文件通过网关 ,网关路由请求到文件服务器上传文件,后台接收的时候都是???号,大神回复下
Comment From: Boonearbear
file upload is supported better through the zuul servlet directly rather than the spring mvc controller. Prefix your uploads with
/zuuland try.
i use your support sugguest , but is not good idear,
Comment From: chenchaoyun0
add this config in zuul service application.properties zuul.servlet-path=/