Skip to content

Commit ba50a8a

Browse files
smatssonAcconut
andauthored
Add call to findPreviousUploads to readme (#251)
* Add call to findPreviousUploads to readme * Missed some examples in usage.md * Update usage.md Co-authored-by: Marius <[email protected]>
1 parent 58fbfb7 commit ba50a8a

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ input.addEventListener("change", function(e) {
4242
}
4343
})
4444

45-
// Start the upload
46-
upload.start()
45+
// Check if there are any previous uploads to continue.
46+
upload.findPreviousUploads().then(function (previousUploads) {
47+
// Found previous uploads so we select the first one.
48+
if (previousUploads.length) {
49+
upload.resumeFromPreviousUpload(previousUploads[0])
50+
}
51+
52+
// Start the upload
53+
upload.start()
54+
})
4755
})
4856
```
4957

docs/usage.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6169
var 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
6485
var upload = new tus.Upload(file, {
6586
endpoint: "http://localhost:1080/files/",
@@ -80,11 +101,11 @@ pauseButton.addEventListener("click", function() {
80101
})
81102

82103
unpauseButton.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
165186
upload.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

Comments
 (0)