Skip to content

Commit

Permalink
Add call to findPreviousUploads to readme (#251)
Browse files Browse the repository at this point in the history
* Add call to findPreviousUploads to readme

* Missed some examples in usage.md

* Update usage.md

Co-authored-by: Marius <[email protected]>
  • Loading branch information
smatsson and Acconut committed Mar 25, 2021
1 parent 58fbfb7 commit ba50a8a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ input.addEventListener("change", function(e) {
}
})

// Start the upload
upload.start()
// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.
if (previousUploads.length) {
upload.resumeFromPreviousUpload(previousUploads[0])
}

// Start the upload
upload.start()
})
})
```

Expand Down
43 changes: 36 additions & 7 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ input.addEventListener("change", function(e) {
}
})

// Start the upload
upload.start()
// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.
if (previousUploads.length) {
upload.resumeFromPreviousUpload(previousUploads[0])
}

// Start the upload
upload.start()
})
})
```

Expand All @@ -60,6 +68,19 @@ This example shows how you can implement a pauseable upload using tus-js-client.
// Obtain file from user input or similar
var file = ...

function startOrResumeUpload(upload) {
// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.
if (previousUploads.length) {
upload.resumeFromPreviousUpload(previousUploads[0])
}

// Start the upload
upload.start()
})
}

// Create the tus upload similar to the example from above
var upload = new tus.Upload(file, {
endpoint: "http://localhost:1080/files/",
Expand All @@ -80,11 +101,11 @@ pauseButton.addEventListener("click", function() {
})

unpauseButton.addEventListener("click", function() {
upload.start()
startOrResumeUpload(upload)
})

// Start the upload by default
upload.start()
startOrResumeUpload(upload)
```

## Example: Let user select upload to resume
Expand Down Expand Up @@ -161,7 +182,7 @@ var upload = new tus.Upload(file, {
}
})

// Start the upload by default
// Start the upload
upload.start()
```

Expand Down Expand Up @@ -198,8 +219,16 @@ input.addEventListener("change", function(e) {
}
})

// Start the upload
upload.start()
// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.
if (previousUploads.length) {
upload.resumeFromPreviousUpload(previousUploads[0])
}

// Start the upload
upload.start()
})
})
```

Expand Down

0 comments on commit ba50a8a

Please sign in to comment.