How to set content length as long value in http header in java?

后端 未结 4 678
执念已碎
执念已碎 2021-01-01 22:48

I am writing a web server in java that is transferring file upto 2GB fine. When I searched for the reason, I found like java HttpServelet only allows us to set the content l

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 23:00

    You can also use below sample code.

    long length = fileObj.length();
    
    if (length <= Integer.MAX_VALUE)
    {
      response.setContentLength((int)length);
    }
    else
    {
      response.addHeader("Content-Length", Long.toString(length));
    }
    

提交回复
热议问题