How to know the file size when uploading via multipart form-data?

前端 未结 2 642
悲&欢浪女
悲&欢浪女 2020-12-20 23:47

I am exercising a simple application with HTML client that uploads a file to the server and must display a progress bar :)

The server is servlet-based, some servlet

相关标签:
2条回答
  • 2020-12-21 00:04

    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")

    0 讨论(0)
  • 2020-12-21 00:28

    I think you have to implement the progress bar in javascript on the client side.

    Anyway, this link gives an explanation of how to do it using 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 ...

    0 讨论(0)
提交回复
热议问题