I am exercising a simple application with HTML client that uploads a file to the server and must display a progress bar :)
我正在使用HTML客户端执行一个简单的应用程序,它将文件上传到服务器并且必须显示进度条:)
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?
服务器是基于servlet的,一些servlet接收多部分内容,解析它等。显然,我知道到目前为止收到的字节数。但是,为了在客户端提供进度条的信息,servlet还需要正在上载的文件的总字节数。知道从哪里获取总字节数?
Thanks!
2 个解决方案
#1
1
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")
内容大小放在Content-Length标题中(参见rfc2616)。在Servlet中,您可以通过request.getContentLength()或reqest.getHeaders(“Content-Length”)获取此标头的值。
#2
2
I think you have to implement the progress bar in javascript on the client side.
我认为你必须在客户端的javascript中实现进度条。
Anyway, this link gives an explanation of how to do it using JQuery.
无论如何,这个链接解释了如何使用JQuery来做到这一点。
The server can obtain the size of the multipart being uploaded from the HTTP request header; see @ilya's answer. However, getting that information and the count(s) of bytes read so far into a stream of HTTP responses that display or update a progress bar would be rather complicated ...
服务器可以从HTTP请求头获取正在上传的多部分的大小;看@ ilya的回答。但是,将此信息和到目前为止读取的字节数计入到显示或更新进度条的HTTP响应流中会相当复杂......
#1
1
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")
内容大小放在Content-Length标题中(参见rfc2616)。在Servlet中,您可以通过request.getContentLength()或reqest.getHeaders(“Content-Length”)获取此标头的值。
#2
2
I think you have to implement the progress bar in javascript on the client side.
我认为你必须在客户端的javascript中实现进度条。
Anyway, this link gives an explanation of how to do it using JQuery.
无论如何,这个链接解释了如何使用JQuery来做到这一点。
The server can obtain the size of the multipart being uploaded from the HTTP request header; see @ilya's answer. However, getting that information and the count(s) of bytes read so far into a stream of HTTP responses that display or update a progress bar would be rather complicated ...
服务器可以从HTTP请求头获取正在上传的多部分的大小;看@ ilya的回答。但是,将此信息和到目前为止读取的字节数计入到显示或更新进度条的HTTP响应流中会相当复杂......