Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

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

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 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?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 ...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...