You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2026/10/16 08:02:50 UTC

(struts-site) branch main updated: WW-3526 docs: describe how to track file upload progress (#359)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/struts-site.git


The following commit(s) were added to refs/heads/main by this push:
     new 897280dfb8 WW-3526 docs: describe how to track file upload progress (#359)
897280dfb8 is described below

commit 897280dfb8772c4a02886040b799fc763d43d62d
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Fri Oct 16 10:02:44 2026 +0200

    WW-3526 docs: describe how to track file upload progress (#359)
    
    Co-authored-by: Claude Opus 5.5 <no...@anthropic.com>
---
 source/core-developers/action-file-upload.md | 51 ++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/source/core-developers/action-file-upload.md b/source/core-developers/action-file-upload.md
index f19f958aa5..b2a704d94b 100644
--- a/source/core-developers/action-file-upload.md
+++ b/source/core-developers/action-file-upload.md
@@ -377,6 +377,57 @@ you can simple set
 
 in struts.xml to start using it.
 
+### Upload Progress
+
+Struts does not track upload progress itself. To show a progress bar, use the browser's `XMLHttpRequest.upload`
+progress events, which report the bytes sent so far without any server-side support:
+
+```js
+const xhr = new XMLHttpRequest();
+xhr.upload.onprogress = (e) => {
+    if (e.lengthComputable) {
+        progressBar.value = e.loaded / e.total;
+    }
+};
+xhr.open('POST', form.action);
+xhr.send(new FormData(form));
+```
+
+If you need progress on the server side, extend one of the parsers and register a Commons FileUpload
+`ProgressListener`:
+
+```java
+public class ProgressTrackingMultiPartRequest extends JakartaMultiPartRequest {
+
+    private HttpServletRequest request;
+
+    @Override
+    public void parse(HttpServletRequest request, String saveDir) throws IOException {
+        this.request = request;
+        super.parse(request, saveDir);
+    }
+
+    @Override
+    protected JakartaServletDiskFileUpload prepareServletFileUpload(Charset charset, Path saveDir) {
+        JakartaServletDiskFileUpload upload = super.prepareServletFileUpload(charset, saveDir);
+        upload.setProgressListener((bytesRead, contentLength, items) -> {
+            // publish bytesRead / contentLength where your application can read it
+        });
+        return upload;
+    }
+}
+```
+
+and register it as the parser in `struts.xml`:
+
+```xml
+<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="progress"
+      class="com.example.ProgressTrackingMultiPartRequest" scope="prototype"/>
+<constant name="struts.multipart.parser" value="progress"/>
+```
+
+The same approach works with `JakartaStreamMultiPartRequest`.
+
 ### Request validation
 
 The `struts.multipart.validationRegex` is used to define a RegEx to be used to validate if the incoming request is a