33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
var tus = require("tus-js-client");
|
|
|
|
$('#uploadBtn').change(function () {
|
|
var file = this.files[0];
|
|
if (typeof file === "undefined") {
|
|
return;
|
|
}
|
|
|
|
// some validations goes here using `file.size` & `file.type`
|
|
|
|
var upload = new tus.Upload(file, {
|
|
// https://github.com/tus/tus-js-client#tusdefaultoptions
|
|
endpoint: "/tus",
|
|
retryDelays: [0, 1000, 3000, 5000, 10000],
|
|
overridePatchMethod: true, // Because production-servers-setup doesn't support PATCH http requests
|
|
chunkSize: 1000 * 1000, // Bytes
|
|
metadata: {
|
|
filename: file.name,
|
|
filetype: file.type
|
|
},
|
|
onError: function (error) {
|
|
// Handle errors here
|
|
},
|
|
onProgress: function (bytesUploaded, bytesTotal) {
|
|
// Reflect values on your progress bar using `bytesTotal` & `bytesUploaded`
|
|
},
|
|
onSuccess: function () {
|
|
// Upload has been completed
|
|
}
|
|
});
|
|
// Start the upload
|
|
upload.start();
|
|
}); |