上传超大文件时出现的,不知道怎么解决,如果设置
[code="java"]con.setChunkedStreamingMode(1024);[/code]
但是很多服务器不支持这种上传方式,我的服务器是tomcat,文件上传组件是struts的文件上传,大家帮我看看这个问题到底怎么解决或者给个方案也行,但我不想修改服务器的代码
![](https://profile-avatar.csdnimg.cn/default.jpg!4)
http 超大文件上传出现 java.lang.OutOfMemoryError: Java heap space
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
10条回答 默认 最新
- 了了与奇奇 2011-01-13 12:39关注
你说得没错,那个是一个Post请求而不是文件上传,你需要模拟一个上传请求,试试配置参数:
[code="java"]
con.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
// Allow Inputs
con.setDoInput(true);// Allow Outputs
con.setDoOutput(true);// Don't use a cached copy.
con.setUseCaches(false);// Use a post method.
con.setRequestMethod("POST");con.setRequestProperty("Connection", "Keep-Alive");
dos = new DataOutputStream( con.getOutputStream() );dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"upload\";"
+ " filename=\"" + exsistingFileName +"\"" + lineEnd);[/code]
摘自:http://www.jguru.com/faq/view.jsp?EID=62798本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报