Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Initial Tus implementation
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],
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();
});
<?php
class TusController {
public function indexAction() {
// Disable views/layout the way suites your framework
$server = new TusPhp\Tus\Server(); // Using File Cache (over Redis) for simpler setup
$server->setApiPath('/tus/index') // tus server endpoint.
->setUploadDir('/tmp'); // uploads dir.
$response = $server->serve();
$response->send();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.