Resumable Uploads
Restricted usage
The usage documented below are for illustrative purposes only. If you have data you would like to upload into the service, contact us at ldh-admin@bcm.edu.
A. tus protocol
Large data uploads may be interrupted by network errors. Alternatively, a user may wish to pause an upload and start again at a later time.
The tus protocol allows resumable uploads over HTTP. The DSS implements v1.0.0 of this protocol.
The path /{tenant}/ns/{namespace}/set/{set}/id/{id} is the same as for regular, non-resumable uploads. However, because of the combination of PATCH, HEAD, and POST requests, along with protocol-specific headers as specified in the tus documentation, it is recommended that you use an existing library to make your client.
Removal of unfinished uploads
The Expiration extension of the protocol is used by the DSS. By default, any uploads not finished within 3 days from the initial request will be restarted from the beginning.
A.1 Example client setup
Client libraries in several languages are available.
A JavaScript implementation is at tus-js-client. An example using this library with the DSS is provided below. Other examples and options are documented at the library's GitHub.
const Fs = require( 'fs' )
const Tus = require( 'tus-js-client' )
const id = 'testid'
const endpoint = `https://${HOST}/ldh-dss/sandbox_tn/ns/ns1/set/set1/id/${id}`
const urlStorageFile = './urlStorage.json'
const chunkSize = 5E6 // adjust as needed
const jwt = '' // retrieve by whichever method you want
const headers = {
Authorization: `Bearer ${jwt}`
}
const file = Fs.createReadStream( './testfile.txt' )
const options = {
endpoint: endpoint,
canStoreURLs: true,
urlStorage: new Tus.FileUrlStorage( urlStorageFile ),
chunkSize: chunkSize,
headers: headers,
onError: function( err ) {
console.log( `Error occurred: ${err}` )
},
onProgress: function( bytesUploaded, bytesTotal ) {
const percentage = ( ( bytesUploaded / bytesTotal ) * 100 ).toFixed( 2 )
console.log( `Tus upload progress: ${bytesUploaded} ${bytesTotal} ${percentage}%` )
},
onSuccess: function() {
console.log( 'Upload finished' )
}
}
const upload = new Tus.Upload( file, options )
const startUpload = ()=>{
upload.findPreviousUploads().then( function( previousUploads ) {
console.log( `${previousUploads.length} previous uploads found` )
if( previousUploads.length ) {
upload.resumeFromPreviousUpload( previousUploads[0] )
}
upload.start()
} )
}
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' // only set for dev hosts
startUpload()A.1.1 Example output
// File is 50 MB
0 previous uploads found
Tus upload progress: 0 50000000 0.00%
Tus upload progress: 65536 50000000 0.13%
Tus upload progress: 327680 50000000 0.66%
Tus upload progress: 1048576 50000000 2.10%
// ...
Tus upload progress: 12883584 50000000 25.77%
Tus upload progress: 13801088 50000000 27.60%
// Script execution interrupted; script restarted
1 previous uploads found
Tus upload progress: 10000000 50000000 20.00%
Tus upload progress: 10065536 50000000 20.13%
Tus upload progress: 10196608 50000000 20.39%
// ...
Tus upload progress: 48080192 50000000 96.16%
Tus upload progress: 49194304 50000000 98.39%
Tus upload progress: 50000000 50000000 100.00%
Upload finished{"tus::node-file-/home/someuser/path/testfile.txt-50000000-1738776269786-https://HOST/ldh-dss/sandbox_tn/ns/ns1/set/set1/id/testid::91911399376":{"size":50000000,"metadata":{},"creationTime":"Wed Feb 05 2025 11:31:26 GMT-0600 (Central Standard Time)","uploadUrl":"https://HOST/ldh-dss/sandbox_tn/ns/ns1/set/set1/id/testid"}}