Skip to content

A pure JavaScript client for the tus resumable upload protocol

License

Notifications You must be signed in to change notification settings

mb21/tus-js-client

This branch is 47 commits behind tus/tus-js-client:main.

Folders and files

NameName
Last commit message
Last commit date
Dec 8, 2023
Feb 2, 2024
Mar 19, 2024
Mar 18, 2024
Mar 18, 2024
Dec 7, 2023
Mar 26, 2023
Oct 8, 2015
Jun 7, 2022
Mar 26, 2023
Sep 9, 2022
Mar 26, 2023
Mar 26, 2023
Apr 6, 2015
Mar 15, 2021
Dec 8, 2023
Apr 8, 2024
Mar 4, 2024
Apr 8, 2024

Repository files navigation

tus-js-client

Tus logo

tus is a protocol based on HTTP for resumable file uploads. Resumable means that an upload can be interrupted at any moment and can be resumed without re-uploading the previous data again. An interruption may happen willingly, if the user wants to pause, or by accident in case of an network issue or server outage.

tus-js-client is a pure JavaScript client for the tus resumable upload protocol and can be used inside browsers, Node.js, React Native and Apache Cordova applications.

Protocol version: 1.0.0

This branch contains tus-js-client v4. If you are looking for the previous major release, after which breaking changes have been introduced, please look at the v3.1.3 tag.

Example

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()
  })
})

Documentation

Build status

Actions Status

License

This project is licensed under the MIT license, see LICENSE.

About

A pure JavaScript client for the tus resumable upload protocol

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.5%
  • TypeScript 1.1%
  • Other 1.4%