AsyncHttpClient 上传两个以上文件 Unable to parse request

Android 码拜 6年前 (2015-07-11) 524次浏览 0个评论

AsyncHttpClient上传两个以上文件到服务端,服务端接收的时候报错
服务端是用Java的 struts2框架写的,tomcat服务器,tomcat设置如下:
<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”100000″
redirectPort=”8443″ URIEncoding=”UTF-8″
maxHttpHeaderSize=”8192″
maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
enableLookups=”false” acceptCount=”100″
disableUploadTimeout=”false” />
我开始以为是客户端上传文件大小出错,所以每次上传两张图片很正常,三张就报错
但是后来我实验了上传一个10多M的文件加一个图片,很正常,但是再增加一张图片就报错。
搞了好久,快疯掉了,各位大侠救命,解决问题马上给分,不胜感激!
每次报错信息都是如下:
九月 27, 2014 7:56:28 下午 org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest warn
警告: Unable to parse request
org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parseRequest(JakartaMultiPartRequest.java:189)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.processUpload(JakartaMultiPartRequest.java:127)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parse(JakartaMultiPartRequest.java:92)
at org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper.<init>(MultiPartRequestWrapper.java:81)
at org.apache.struts2.dispatcher.Dispatcher.wrapRequest(Dispatcher.java:803)
at org.apache.struts2.dispatcher.ng.PrepareOperations.wrapRequest(PrepareOperations.java:134)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:1005)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:903)
at java.io.InputStream.read(InputStream.java:101)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:100)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:70)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:347)
… 19 more

 
主要的出错其实是:
Processing of multipart/form-data request failed. Stream ended unexpectedly
哪位能告知,或者提示一点思路,不胜感激

20分

从提示信息“Stream ended unexpectedly”来看,可能是你的android程序没有把数据传完就断开连接了。
 
是的,我用jsp页面上传是正常的。
难道是开源库的bug?

20分

是怎么添加附件的,是不是上传的格式编码问题,你试下两张能压缩上传么?
 
	private boolean inPutFile(RequestParams params, int i, String path, String fileDescription) throws FileNotFoundException {
		File file = new File(path);
	    if(file.exists() && file.length()>0){
	    	params.put("image" + i, file);
		    params.put("desc" + i, fileDescription);
		    params.put("fileName" + i, file.getName());
		    return true;
	    }
	    else{
		    System.out.println("文件不存在");
		}

	    return false;
	}

我是这样添加附件的

 
问题我已经解决了,我换了xutils框架,用法和AsyncHttpClient一样的。然后就可以正常上传了,没有上传个数的限制。
强烈怀疑是AsyncHttpClient框架的bug
 
用第三方库的风险在于可控性很弱,出了问题不知道原因。可能是第三方库的bug,也可能是用的不对。
 
IOS端用文件流上传也是可以的,看来服务端是没什么问题的。
多谢各位,结贴给分!
 
xutils框架好用吗?学习中
 
请问一下楼主 服务端代码是如何接受到上传的文件流的呢!

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明AsyncHttpClient 上传两个以上文件 Unable to parse request
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!