Skip to content

Add a resumable upload to a resource, sent in chunks over tus (11.x) - #2011

Draft
reiern70 wants to merge 2 commits into
wicket-11.xfrom
resumable-upload-11.x
Draft

reiern70 wants to merge 2 commits into
wicket-11.xfrom
resumable-upload-11.x

Conversation

@reiern70

Copy link
Copy Markdown
Contributor

Backport of #2010 to wicket-11.x.

No API break, only additions:

  • the new package in wicket-extensions;
  • FileUploadToResourceField.getUploadCallbackUrl(), protected final;
  • the export of org.apache.wicket.markup.html.form.upload.resource in the module-info of wicket-core, which held public API but was only opened.

japicmp against 11.0.0 reports no incompatible change. The default serialVersionUID of FileUploadToResourceField changes, as with any change to a component. Nothing to migrate.

Verified on this branch:

  • mvn clean install -Pjs-test is green, japicmp included: 3373 Java tests, and 213 and 212 JavaScript tests (jQuery and vanilla engines), none failing.

FileUploadToResourceField sends all its files in one multipart request.
After a dropped connection, a proxy timeout or a reload of the page, a
large file has to be sent again from its first byte. It cannot be paused,
and a proxy may refuse a request that large.

wicket-extensions gets ResumableUploadToResourceField, a subclass of
FileUploadToResourceField. Each of its files goes in chunks, over the
open tus protocol 1.0, to a ResumableUploadResourceReference that the
application mounts once, as it mounts FileUploadResourceReference. Each
upload can be paused, resumed and canceled. After a broken connection it
goes on from the byte the server got to, once the browser is online
again. The browser remembers unfinished uploads in localStorage, so the
same file chosen after a reload or a browser restart goes on where it
stopped. Once a file is whole the reference hands it to the application's
IUploadsFileManager, and the field reports it to onUploadSuccess() as an
UploadInfo, exactly as for the multipart resource. The limits, the
failure and cancel hooks, FileDropZoneBehavior and FileListBehavior all
work as before. The list shows each file's progress, with buttons to
pause, resume and cancel it.

The script is plain JavaScript and builds on Wicket.FileUploadToResourceField.
Neither side adds a dependency. Every request carries the field's id and
limits, signed with the application's crypt, as the query of the
multipart resource does. An upload belongs to the HTTP session that
created it. The reference limits the size of a file and of a chunk, the
uploads of a session and of all sessions, and the free space on disk. It
deletes uploads the browser has not touched for a while, those of a
session that ends, and all of them when the application stops. Wicket's
filter answers OPTIONS itself, so the resource does not announce its
tus version there; tus clients do not need it.

Three small changes in wicket-core make the subclass possible.
FileUploadToResourceField gets getUploadCallbackUrl(), so a subclass
rendering its own script reports to the same callback. module-info now
exports org.apache.wicket.markup.html.form.upload.resource: the package
holds public API but was only opened, so an application on the module
path could not use the upload to a resource. Javadoc now covers that
package, and its raw generics are fixed.

Applications that do not use the new field see no change. The upload
examples get a "Resumable upload to a resource" page.
A React application or a mobile app has no ResumableUploadToResourceField
to sign its requests, so the resource refused all of them.
ResumableUploadResourceReference.newQuery() now creates the signed query
for an id the application chooses and limits it sets. The names of the
headers that carry the stored file name and the error key are now public
constants of the reference. A client like that can complete an upload
and hand the stored name back to the application, which finds the file
in the file manager under its id.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.52468% with 112 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.91%. Comparing base (f8d1873) to head (2b48818).

Additional details and impacted files
@@                Coverage Diff                @@
##             wicket-11.x    #2011      +/-   ##
=================================================
+ Coverage          62.73%   62.91%   +0.17%     
- Complexity         11512    11682     +170     
=================================================
  Files               1254     1260       +6     
  Lines              48669    49215     +546     
  Branches            6846     6903      +57     
=================================================
+ Hits               30532    30962     +430     
- Misses             15460    15549      +89     
- Partials            2677     2704      +27     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants