Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tus-js-client

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tus-js-client

A pure JavaScript client for the tus resumable upload protocol

  • 4.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
220K
decreased by-3.67%
Maintainers
2
Weekly downloads
 
Created

What is tus-js-client?

The tus-js-client is a JavaScript client for the tus resumable upload protocol. It allows you to upload large files to a server in a reliable and resumable manner, meaning that if the upload is interrupted, it can be resumed from where it left off.

What are tus-js-client's main functionalities?

Resumable File Upload

This feature allows you to upload a file to a server in a resumable manner. The upload can be paused and resumed, and it will automatically retry if it fails.

const tus = require('tus-js-client');
const file = document.querySelector('input[type="file"]').files[0];
const upload = new tus.Upload(file, {
  endpoint: 'https://tusd.tusdemo.net/files/',
  retryDelays: [0, 1000, 3000, 5000],
  metadata: {
    filename: file.name,
    filetype: file.type
  },
  onError: function(error) {
    console.log('Failed because: ' + error);
  },
  onProgress: function(bytesUploaded, bytesTotal) {
    const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
    console.log(bytesUploaded, bytesTotal, percentage + '%');
  },
  onSuccess: function() {
    console.log('Download %s from %s', upload.file.name, upload.url);
  }
});
upload.start();

Custom Headers

This feature allows you to add custom headers to the upload request, such as an Authorization header for authentication purposes.

const tus = require('tus-js-client');
const file = document.querySelector('input[type="file"]').files[0];
const upload = new tus.Upload(file, {
  endpoint: 'https://tusd.tusdemo.net/files/',
  headers: {
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
  },
  onError: function(error) {
    console.log('Failed because: ' + error);
  },
  onSuccess: function() {
    console.log('Download %s from %s', upload.file.name, upload.url);
  }
});
upload.start();

Chunked Uploads

This feature allows you to upload files in chunks, which can be useful for large files. You can specify the chunk size, and the upload will be split into multiple smaller requests.

const tus = require('tus-js-client');
const file = document.querySelector('input[type="file"]').files[0];
const upload = new tus.Upload(file, {
  endpoint: 'https://tusd.tusdemo.net/files/',
  chunkSize: 5242880, // 5MB
  onError: function(error) {
    console.log('Failed because: ' + error);
  },
  onSuccess: function() {
    console.log('Download %s from %s', upload.file.name, upload.url);
  }
});
upload.start();

Other packages similar to tus-js-client

Keywords

FAQs

Package last updated on 11 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc