I have the following java script code I tried to upload multiples videos to my Viemo account now the problem is when I upload multiples videos only one of them work other videos will corruption and not working what is the exactly my problem with this code.
<script src="https://cdn.jsdelivr.net/npm/tus-js-client@2.1.1/dist/tus.js"></script>
<script>
document.getElementById('browse').addEventListener("input", function (e) {
for (var i = 0; i < e.target.files.length; i++) {
var file = e.target.files[i];
var myToken = "MyToeknNumber";
var url = 'https://api.vimeo.com/me/videos'
var xhr = new XMLHttpRequest()
xhr.open('POST', 'https://api.vimeo.com/me/videos', true)
xhr.setRequestHeader('Authorization', 'Bearer ' + myToken)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.setRequestHeader('Accept', 'application/vnd.vimeo.*+json;version=3.4')
xhr.onload = function (e) {
if (e.target.status < 400) {
console.log(e.target.status) //this returns status 200
var response = JSON.parse(e.target.responseText)
var upload = new tus.Upload(file, {
uploadUrl: response.upload.upload_link,
retryDelays: [0, 1000, 3000, 5000],
metadata: {
filename: file.name,
filetype: file.type
},
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 () {
console.log("Download %s from %s", upload.file.name, upload.url)
}
})
// Start the upload
upload.start()
} else {
console.log("This is a developer error: " + e)
console.log(e.target.status)
}
}.bind(this)
xhr.send(JSON.stringify({
upload: {
approach: 'tus',
size: file.size
},
name: 'Name of the Video' + i + '',
description: "Video description"
}));
} // end the loop
})
</script>
I wanted to upload all videos to Vimeo just one file will working that has smallest size.