mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-29 04:50:05 +00:00
Turn Tus upload into a proper promise
This commit is contained in:
parent
fec8e0df16
commit
9f4e412762
1 changed files with 45 additions and 21 deletions
|
|
@ -35,29 +35,53 @@ export default class Tus10 extends Plugin {
|
|||
})
|
||||
|
||||
// Create a new tus upload
|
||||
const upload = new tus.Upload(file, {
|
||||
endpoint: this.opts.endpoint,
|
||||
onError: error => {
|
||||
return Promise.reject('Failed because: ' + error)
|
||||
},
|
||||
onProgress: (bytesUploaded, bytesTotal) => {
|
||||
let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
|
||||
percentage = Math.round(percentage)
|
||||
// self.setProgress(percentage, current, total)
|
||||
return new Promise((resolve, reject) => {
|
||||
const upload = new tus.Upload(file, {
|
||||
endpoint: this.opts.endpoint,
|
||||
onError: error => {
|
||||
reject('Failed because: ' + error)
|
||||
},
|
||||
onProgress: (bytesUploaded, bytesTotal) => {
|
||||
let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
|
||||
percentage = Math.round(percentage)
|
||||
|
||||
// Dispatch progress event
|
||||
this.core.emitter.emit('progress', {
|
||||
plugin: this,
|
||||
percentage: percentage
|
||||
})
|
||||
},
|
||||
onSuccess: () => {
|
||||
this.core.log(`Download ${upload.file.name} from ${upload.url}`)
|
||||
return Promise.resolve(upload)
|
||||
}
|
||||
// Dispatch progress event
|
||||
this.core.emitter.emit('progress', {
|
||||
plugin: this,
|
||||
percentage: percentage
|
||||
})
|
||||
},
|
||||
onSuccess: () => {
|
||||
this.core.log(`Download ${upload.file.name} from ${upload.url}`)
|
||||
resolve(upload)
|
||||
}
|
||||
})
|
||||
upload.start()
|
||||
})
|
||||
// Start the upload
|
||||
return upload.start()
|
||||
|
||||
// const upload = new tus.Upload(file, {
|
||||
// endpoint: this.opts.endpoint,
|
||||
// onError: error => {
|
||||
// return Promise.reject('Failed because: ' + error)
|
||||
// },
|
||||
// onProgress: (bytesUploaded, bytesTotal) => {
|
||||
// let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
|
||||
// percentage = Math.round(percentage)
|
||||
// // self.setProgress(percentage, current, total)
|
||||
//
|
||||
// // Dispatch progress event
|
||||
// this.core.emitter.emit('progress', {
|
||||
// plugin: this,
|
||||
// percentage: percentage
|
||||
// })
|
||||
// },
|
||||
// onSuccess: () => {
|
||||
// this.core.log(`Download ${upload.file.name} from ${upload.url}`)
|
||||
// return Promise.resolve(upload)
|
||||
// }
|
||||
// })
|
||||
// // Start the upload
|
||||
// return upload.start()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue