Your loop calls request.getParts()
, which returns a Collection<Part>
and thus require the browser input to be fully parsed before you can even enter the first iteration of your loop. What you call a file upload is really a HTTP request that looks like this:
GET /fileUpload.do
Content-Type: multipart/form-data; boundary=--limit
--limit
content-disposition: form-data; name="description"
content-type: text/plain
This is the description of the file
--limit
content-disposition: form-data; name="image"
content-type: image/png
lksdf82203j1897239481231kadlqcdladaod82y3o98dqjdhdqkdh
q9wrcfdhlqhfoqwfn92q38uycrnwehrnqolwhfrnoq83y018yn8cy2
oqwdfopiqweuroq338rquncqwurqwercqfjqwcngreydisajf238jd
...
To get the list of the parts that make up the request, the framework must first parse the whole request, and it may take a while depending on the file size and network speed.
You may speed things up by parsing the raw InputStream
returned by request.getInputStream()
by yourself, but currently I don't know any library that lets you process a multipart envelope in a streaming fashion (like, say, the SAX API for XML documents). Also, I'm not entirely sure how this will ever affect the visible performance of the application.