2

I’m new to tus and I’m using tus-js-client. I’m following the example in this link https://github.com/tus/tus-js-client/blob/master/docs/usage.md#example-upload-to-vimeo.

I was able to successfully upload a video on Vimeo but I would like to set the title/name and description in advance. And also the optional onSuccess function is not returning anything. I would like to get the video details that I’ve uploaded successfully like the clipid.

Are these things something possible to do on tus-js-client? Below is my code for reference.

function UploadVideoTusJs(uploadUrl, videoFile) {
    var upload = new tus.Upload(videoFile.files[0], {
        uploadUrl: uploadUrl,
        metadata: {
            name: videoFile.files[0].name, // not working
            description: "Test", // not working
        },
        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 (data) {
            console.log(data); //returns undefined
            console.log("Download %s from %s", upload.file.name, upload.url);
        },
        onAfterResponse: function (req, res) {
            var url = req.getURL()
            var value = res.getHeader("X-My-Header")
            console.log(`Request for ${url} responded with ${value}`)
        }
    });

    // Start the upload by default
    upload.start();
}

-- Dan

dahnfalomi
  • 23
  • 3

1 Answers1

1

Vimeo's implementation of tus is a bit different as the "creation" step is done using the Vimeo API, not using tus. If you want to provide metadata like name or description, that should be provided with the initial API request, which should look something like this:

var settings = {
  "url": "https://api.vimeo.com/me/videos",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Accept": "application/vnd.vimeo.*+json;version=3.4",
    "Content-Type": "application/json",
    "Authorization": "Bearer TOKEN"
  },
  "data": JSON.stringify({"upload":{"approach":"tus","size":666666666},"name":"name","description":"description"}),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Hope this points you in the right direction!

Tommy Penner
  • 2,440
  • 1
  • 7
  • 13