@@ -47,8 +47,16 @@ input.addEventListener("change", function(e) {
4747 }
4848 })
4949
50- // Start the upload
51- upload .start ()
50+ // Check if there are any previous uploads to continue.
51+ upload .findPreviousUploads ().then (function (previousUploads ) {
52+ // Found previous uploads so we select the first one.
53+ if (previousUploads .length ) {
54+ upload .resumeFromPreviousUpload (previousUploads[0 ])
55+ }
56+
57+ // Start the upload
58+ upload .start ()
59+ })
5260})
5361```
5462
@@ -60,6 +68,19 @@ This example shows how you can implement a pauseable upload using tus-js-client.
6068// Obtain file from user input or similar
6169var file = ...
6270
71+ function startOrResumeUpload (upload ) {
72+ // Check if there are any previous uploads to continue.
73+ upload .findPreviousUploads ().then (function (previousUploads ) {
74+ // Found previous uploads so we select the first one.
75+ if (previousUploads .length ) {
76+ upload .resumeFromPreviousUpload (previousUploads[0 ])
77+ }
78+
79+ // Start the upload
80+ upload .start ()
81+ })
82+ }
83+
6384// Create the tus upload similar to the example from above
6485var upload = new tus.Upload (file, {
6586 endpoint: " http://localhost:1080/files/" ,
@@ -80,11 +101,11 @@ pauseButton.addEventListener("click", function() {
80101})
81102
82103unpauseButton .addEventListener (" click" , function () {
83- upload . start ( )
104+ startOrResumeUpload (upload )
84105})
85106
86107// Start the upload by default
87- upload . start ( )
108+ startOrResumeUpload (upload )
88109```
89110
90111## Example: Let user select upload to resume
@@ -161,7 +182,7 @@ var upload = new tus.Upload(file, {
161182 }
162183})
163184
164- // Start the upload by default
185+ // Start the upload
165186upload .start ()
166187```
167188
@@ -198,8 +219,16 @@ input.addEventListener("change", function(e) {
198219 }
199220 })
200221
201- // Start the upload
202- upload .start ()
222+ // Check if there are any previous uploads to continue.
223+ upload .findPreviousUploads ().then (function (previousUploads ) {
224+ // Found previous uploads so we select the first one.
225+ if (previousUploads .length ) {
226+ upload .resumeFromPreviousUpload (previousUploads[0 ])
227+ }
228+
229+ // Start the upload
230+ upload .start ()
231+ })
203232})
204233```
205234
0 commit comments