tus js client
v4.2.3
TUS是基於HTTP的協議,用於重新啟動文件上傳。可重新啟動意味著可以隨時中載上傳,並且可以恢復而不重新上傳以前的數據。如果用戶想暫停,或者在網絡發行或服務器中斷時,可能會願意發生中斷。
TUS-JS-CLIENT是TUS可重新上傳協議的純JavaScript客戶端,可以在瀏覽器, Node.js , React Native和Apache Cordova應用程序中使用。
協議版本: 1.0.0
該分支包含TUS-JS-CLIENT V4。如果您正在尋找以前的主要版本,然後引入了破壞變化,請查看v3.1.3標籤。
input . addEventListener ( 'change' , function ( e ) {
// Get the selected file from the input element
var file = e . target . files [ 0 ]
// Create a new tus upload
var upload = new tus . Upload ( file , {
endpoint : 'http://localhost:1080/files/' ,
retryDelays : [ 0 , 3000 , 5000 , 10000 , 20000 ] ,
metadata : {
filename : file . name ,
filetype : file . type ,
} ,
onError : function ( error ) {
console . log ( 'Failed because: ' + error )
} ,
onProgress : function ( bytesUploaded , bytesTotal ) {
var percentage = ( ( bytesUploaded / bytesTotal ) * 100 ) . toFixed ( 2 )
console . log ( bytesUploaded , bytesTotal , percentage + '%' )
} ,
onSuccess : function ( ) {
console . log ( 'Download %s from %s' , upload . file . name , upload . url )
} ,
} )
// 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 ( )
} )
} ) 該項目已根據MIT許可獲得許可,請參見LICENSE 。