通过分段表单数据上传时如何知道文件大小? [英] How to know the file size when uploading via multipart form-data?
问题描述
我正在使用HTML客户端运行一个简单的应用程序,该应用程序将文件上传到服务器,并且必须显示进度栏:)
I am exercising a simple application with HTML client that uploads a file to the server and must display a progress bar :)
服务器是基于servlet的,一些servlet接收多部分内容,然后对其进行解析等.显然,每时每刻我都知道到目前为止接收到的字节数.但是,为了在客户端提供进度条的信息,servlet还需要文件的字节总数,该文件正被上传.知道从哪里获取字节总数吗?
The server is servlet-based, some servlet receives the multipart content, parses it etc. Obviously, at every moment I know the number of bytes received so far. However in order to supply an info for the progress bar on the client side a servlet also needs the total number of bytes for the file, which is being uploaded. Any idea where to get the total number of bytes from please?
谢谢!
推荐答案
内容大小位于Content-Length标头中(请参见 rfc2616 ).在Servlet中,您可以通过request.getContentLength()
或reqest.getHeaders("Content-Length")
Size of content are placed in Content-Length header (see rfc2616). In Servlet you can get this header's value by request.getContentLength()
or reqest.getHeaders("Content-Length")
这篇关于通过分段表单数据上传时如何知道文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!