request.getContentLength() return 0 when file size is greater than 2gb

我与影子孤独终老i 提交于 2020-01-17 13:43:29

问题


Using a file upload in my project as :

 <s:form id="uploadData" action="UploadAction" namespace="xyz"   validateFields="false" method="post"    enctype="multipart/form-data">

But the request.getContentLength() method returns correct value for less than 2 gb and 0 for anything above it.

The probable reason being datatype of the content-length as int. Is there any other way where the request parameter: content-length can be converted into long type in order to support uploads greater than 2gb.

please guide us how to convert the content length request header to long to support file upload greater than 2gb


回答1:


It's because the getContentLength() method in the Servlet API is defined as int. Actually, it should return -1 for files (requests) bigger than 2gb.

If you're using Servlet API 3.1 (e.g. Tomcat 8), you can use getContentLengthLong() method.



来源:https://stackoverflow.com/questions/34741419/request-getcontentlength-return-0-when-file-size-is-greater-than-2gb

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