当文件大小大于2gb时,request.getContentLength()返回0 [英] request.getContentLength() return 0 when file size is greater than 2gb

查看:278
本文介绍了当文件大小大于2gb时,request.getContentLength()返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中使用文件上传:

 < s:form id =uploadDataaction =UploadAction namespace =xyzvalidateFields =falsemethod =postenctype =multipart / form-data> 

但是request.getContentLength()方法返回小于2 gb的正确值,它。
$ b 可能的原因是内容长度的
数据类型为int。有没有其他的方式,请求参数:content-length可以转换为长型
,以支持大于2GB的上传。

请指导我们如何将内容长度请求头转换为long来支持大于2GB的文件上传 解决方案

这是因为 code> INT 。实际上,它应该为大于2GB的文件(请求)返回 -1

如果你使用Servlet API 3.1(例如Tomcat 8),您可以使用 getContentLengthLong()方法。


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

解决方案

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.

这篇关于当文件大小大于2gb时,request.getContentLength()返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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