Repository navigation
Conversation
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.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2010 +/- ##
============================================
+ Coverage 63.06% 63.26% +0.19%
- Complexity 11691 11866 +175
============================================
Files 1255 1261 +6
Lines 48921 49467 +546
Branches 6922 6979 +57
============================================
+ Hits 30854 31297 +443
- Misses 15386 15463 +77
- Partials 2681 2707 +26 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
FileUploadToResourceFieldsends 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.This adds
ResumableUploadToResourceFieldtowicket-extensions. It is aFileUploadToResourceFieldwhose files each go in chunks, over the open tus protocol 1.0, to aResumableUploadResourceReference. Each upload can be paused, resumed and canceled. After a broken connection it goes on from the byte the server got to. Once the user chooses the same file again after a reload of the page, or a restart of the browser, it goes on where it stopped.How it works
IUploadsFileManager. The field reports it toonUploadSuccess()as anUploadInfo, through the callback of its parent.onUploadFailure(),onUploadCanceled(), the limits (maxSize,fileMaxSize,fileCountMax),startUpload()/cancelUpload(),FileDropZoneBehaviorandFileListBehaviorall behave as before.pauseUpload()andresumeUpload()are new.Wicket.ResumableUploadToResourceFieldbuilds on the prototype ofWicket.FileUploadToResourceField, so choosing, dropping and listing files are the parent's code. The list shows each upload with a<progress>, its state, and buttons to pause or resume it and to cancel it. A configurable number of files go at the same time while the others wait. A failed request is retried with backoff, and an upload waits foronlinewhen the browser went offline. The URLs of unfinished uploads are kept inlocalStorageby the name, size and date of their file, never their content, sosetRemembering(false)turns that off.X-HTTP-Method-Overridefor proxies that refusePATCH. Bytes go into a file of their own per upload. A chunk that breaks off keeps what arrived, and the browser asks withHEADand goes on from there. A refusal carries the resource key of its error inWicket-Upload-Error, which the field words. The answer that completes an upload carries the stored name inWicket-Upload-File-Name.Tus-Resumableis refused. The reference limits the size of a file and of a chunk, the uploads of a session (count and bytes) and of all sessions, and keeps a minimum of free disk space. Uploads the browser has not touched for 30 minutes (by default) are deleted, and so are those of a session that ends, and all of them when the application stops.wicket-core:FileUploadToResourceField.getUploadCallbackUrl()(protected final) lets a subclass rendering its own script report to the same callback.module-infonow exportsorg.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.@params with raw generics there are fixed.Testing
ResumableUploadToResourceFieldTest, 19 tests with WicketTester: the protocol (create, chunks,HEAD,DELETE, method override, offsets that do not follow, chunks that break off, an empty file), the signed grant, the limits, sessions, expiry, cleanup when the application stops, the hand-over to the file manager and the field, and a reload that completes an upload under the new field.resumable-upload-test.js, 14 QUnit tests with a fake XHR, run against both the jQuery and the vanilla Ajax engine: chunks and the report, pause and resume, a retry after a broken connection, waiting while offline, resuming an upload remembered from an earlier page or starting over when the server lost it, refusals and lost uploads, cancel withDELETE, limits checked before anything is sent, parallel uploads, an empty file, and a new rendering taking over the uploads.mvn clean install -Pjs-testis green: 3549 Java tests, and 264 and 263 JavaScript tests (jQuery and vanilla engines), none failing.The example in headless Chrome against Jetty, with the network throttled through the DevTools protocol:
HEADfrom where it stopped after the same file was chosen again;The SHA-256 of every stored file matched the original.
Backported to
wicket-11.xin #2011: no API break there.Open questions
wicket-extensionsthe right home, or should it sit next toFileUploadToResourceFieldinwicket-core?localStoragebe on by default?