使用 tus-js-client 上传到 vimeo
Upload to vimeo with tus-js-client
我是 tus 的新手,我正在使用 tus-js-client。我正在按照此 link https://github.com/tus/tus-js-client/blob/master/docs/usage.md#example-upload-to-vimeo.
中的示例
我能够在 Vimeo 上成功上传视频,但我想提前设置 title/name 和描述。而且可选的 onSuccess 函数也没有返回任何东西。我想获取上传成功的视频详情如clipid
这些东西可以在 tus-js-client 上做吗?下面是我的代码供参考。
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();
}
--丹
Vimeo 的 tus 实现有点不同,因为 "creation" step 是使用 Vimeo API 完成的,而不是使用 tus。如果您想提供名称或描述之类的元数据,应在初始 API 请求中提供,该请求应如下所示:
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);
});
希望这能为您指明正确的方向!
我是 tus 的新手,我正在使用 tus-js-client。我正在按照此 link https://github.com/tus/tus-js-client/blob/master/docs/usage.md#example-upload-to-vimeo.
中的示例我能够在 Vimeo 上成功上传视频,但我想提前设置 title/name 和描述。而且可选的 onSuccess 函数也没有返回任何东西。我想获取上传成功的视频详情如clipid
这些东西可以在 tus-js-client 上做吗?下面是我的代码供参考。
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();
}
--丹
Vimeo 的 tus 实现有点不同,因为 "creation" step 是使用 Vimeo API 完成的,而不是使用 tus。如果您想提供名称或描述之类的元数据,应在初始 API 请求中提供,该请求应如下所示:
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);
});
希望这能为您指明正确的方向!