How to use tus-js-client - 10 common examples

To help you get started, we’ve selected a few tus-js-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github collectiveaccess / providence / js / mediauploader.js View on Github external
//console.log("Stopping queue because max connections have been reached", state.connections, state.connections.length);
                return;
            }
            let file = queue.shift();
            if(!file) { continue; }

            let connectionIndex = state.connectionIndex;
            let relPath = file.webkitRelativePath ? file.webkitRelativePath : file.path;
            if(relPath) {
                let tmp = relPath.split(/\//);
                tmp.pop();
                relPath  = tmp.join('/');
            }

			// Set up tus upload process for file, with handlers for success, error and progress
            let upload = new tus.Upload(file, {
                endpoint: this.props.endpoint + '/tus',
                retryDelays: [0, 1000, 3000, 5000],
                chunkSize: 1024 * 512,      // TODO: make configurable
                metadata: {
                    filename: '.' + file.name + '.part',
                    sessionKey: state.sessionKey,
                    relativePath: relPath
                },
                onBeforeRequest: function (req) {
					var xhr = req.getUnderlyingObject()
					xhr.setRequestHeader('x-session-key', state.sessionKey);
				},
                onError: (error) => {
                    let state = {...that.state};
					// error during transfer
					let error_resp = JSON.parse(error.originalResponse.getBody());
github reactbits / fiber / components / message / uploadbutton.jsx View on Github external
function uploadFile(file, callback = _.noop) {
  // const upload = new Upload(file);
  // upload.on('end', res => {
  //   console.log(res);
  // });
  // const options = {
  //   path: window.UPLOAD_PATH || '/api/uploads/',
  // };
  // upload.to(options);

  // Create a new tus upload
  const upload = new tus.Upload(file, {
    // TODO enable resumable uploads
    resume: false,
    endpoint: window.UPLOAD_PATH || '/api/uploads/',
    onError(err) {
      console.log('upload failed:', err);
      callback(null, err);
    },
    onProgress(bytesUploaded, bytesTotal) {
      const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2);
      console.log('progress %s/%s, %s', bytesUploaded, bytesTotal, `${percentage}%`);
    },
    onSuccess() {
      console.log('download %s from %s', upload.file.name, upload.url);
      callback({ name: upload.file.name, url: upload.url });
    },
  });
github DS3Lab / easeml / client / javascript / easemlclient / src / datasets.js View on Github external
return new Promise((resolve, reject) => {
    var upload = new tus.Upload(data, {
      endpoint: urljoin(this.baseURL, 'datasets', id, 'upload'),
      retryDelays: [0, 1000, 3000, 5000],
      metadata: {
        filename: filename
      },
      headers: this.authHeader,
      onProgress: onProgress,
      // chunkSize: 10000,
      onSuccess: () => resolve(),
      onError: (e) => reject(e)
    })

    // Start the upload
    upload.start()
  })
}
github transloadit / uppy / packages / @uppy / companion / src / server / Uploader.js View on Github external
uploadTus () {
    const fname = path.basename(this.options.path)
    const ftype = this.options.metadata.type
    const metadata = Object.assign({ filename: fname, filetype: ftype }, this.options.metadata || {})
    const file = fs.createReadStream(this.options.path)
    const uploader = this

    // @ts-ignore
    this.tus = new tus.Upload(file, {
      endpoint: this.options.endpoint,
      uploadUrl: this.options.uploadUrl,
      // @ts-ignore
      uploadLengthDeferred: false,
      resume: true,
      retryDelays: [0, 1000, 3000, 5000],
      uploadSize: this.bytesWritten,
      metadata,
      /**
       *
       * @param {Error} error
       */
      onError (error) {
        logger.error(error, 'uploader.tus.error')
        uploader.emitError(error)
      },
github DefinitelyTyped / DefinitelyTyped / types / tus-js-client / tus-js-client-tests.ts View on Github external
uploadUrl: "",
    uploadSize: 50,
    overridePatchMethod: true,
    retryDelays: [10, 20, 50],
    removeFingerprintOnSuccess: true
});

upload.start();

upload.abort();
upload.abort(true);
upload.abort(true, (err?: Error) => {
    console.log("Failed because: " + err);
});

const upload2 = new Tus.Upload(file, {
	endpoint: ""
});

const reader = {
    read: () => Promise.resolve({ done: true, value: '' }),
};
const upload3 = new Tus.Upload(reader, {
    endpoint: '',
    uploadLengthDeferred: true,
});

Tus.Upload.terminate('https://myurl.com', {
	endpoint: ""
});
github DefinitelyTyped / DefinitelyTyped / types / tus-js-client / tus-js-client-tests.ts View on Github external
upload.start();

upload.abort();
upload.abort(true);
upload.abort(true, (err?: Error) => {
    console.log("Failed because: " + err);
});

const upload2 = new Tus.Upload(file, {
	endpoint: ""
});

const reader = {
    read: () => Promise.resolve({ done: true, value: '' }),
};
const upload3 = new Tus.Upload(reader, {
    endpoint: '',
    uploadLengthDeferred: true,
});

Tus.Upload.terminate('https://myurl.com', {
	endpoint: ""
});
github DefinitelyTyped / DefinitelyTyped / types / tus-js-client / tus-js-client-tests.ts View on Github external
import * as Tus from 'tus-js-client';

const isSupported = Tus.isSupported;
const canStoreURLs = Tus.canStoreURLs;
const defaultChunkSize = Tus.defaultOptions.chunkSize;

const file = new File(["foo"], "foo.txt", {
  type: "text/plain",
});

const upload = new Tus.Upload(file, {
    endpoint: "",
    fingerprint: (file: File) => file.name,
    resume: true,
    metadata: {
        filename: "foo.txt"
    },
    onProgress: (bytesSent: number, bytesTotal: number) => {
        const percentage = (bytesSent / bytesTotal * 100).toFixed(2);
        console.log(bytesSent, bytesTotal, percentage + "%");
    },
    onChunkComplete: (chunkSize: number, bytesAccepted: number) => {},
    onSuccess: () => {
    	console.log("Download from %s complete", upload.url);
    },
    onError: (error: Error) => {
    	console.log("Failed because: " + error);
github DefinitelyTyped / DefinitelyTyped / types / tus-js-client / tus-js-client-tests.ts View on Github external
import * as Tus from 'tus-js-client';

const isSupported = Tus.isSupported;
const canStoreURLs = Tus.canStoreURLs;
const defaultChunkSize = Tus.defaultOptions.chunkSize;

const file = new File(["foo"], "foo.txt", {
  type: "text/plain",
});

const upload = new Tus.Upload(file, {
    endpoint: "",
    fingerprint: (file: File) => file.name,
    resume: true,
    metadata: {
        filename: "foo.txt"
    },
    onProgress: (bytesSent: number, bytesTotal: number) => {
        const percentage = (bytesSent / bytesTotal * 100).toFixed(2);
        console.log(bytesSent, bytesTotal, percentage + "%");
github DefinitelyTyped / DefinitelyTyped / types / tus-js-client / tus-js-client-tests.ts View on Github external
import * as Tus from 'tus-js-client';

const isSupported = Tus.isSupported;
const canStoreURLs = Tus.canStoreURLs;
const defaultChunkSize = Tus.defaultOptions.chunkSize;

const file = new File(["foo"], "foo.txt", {
  type: "text/plain",
});

const upload = new Tus.Upload(file, {
    endpoint: "",
    fingerprint: (file: File) => file.name,
    resume: true,
    metadata: {
        filename: "foo.txt"
    },
    onProgress: (bytesSent: number, bytesTotal: number) => {
        const percentage = (bytesSent / bytesTotal * 100).toFixed(2);
        console.log(bytesSent, bytesTotal, percentage + "%");
    },
github DefinitelyTyped / DefinitelyTyped / types / tus-js-client / tus-js-client-tests.ts View on Github external
import * as Tus from 'tus-js-client';

const isSupported = Tus.isSupported;
const canStoreURLs = Tus.canStoreURLs;
const defaultChunkSize = Tus.defaultOptions.chunkSize;

const file = new File(["foo"], "foo.txt", {
  type: "text/plain",
});

const upload = new Tus.Upload(file, {
    endpoint: "",
    fingerprint: (file: File) => file.name,
    resume: true,
    metadata: {
        filename: "foo.txt"
    },
    onProgress: (bytesSent: number, bytesTotal: number) => {
        const percentage = (bytesSent / bytesTotal * 100).toFixed(2);

tus-js-client

A pure JavaScript client for the tus resumable upload protocol

MIT
Latest version published 3 months ago

Package Health Score

89 / 100
Full package analysis