I am trying to make uploads to the vimeo platform using the tus library here . Below is a code snippet of how i initiate this upload process:
document.getElementById('browse').addEventListener("input", function(e) {
// Get the selected file from the input element
var file = e.target.files[0]
var myToken = document.getElementById('accessToken')
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.value)
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)
// Create a new tus upload
var upload = new tus.Upload(file, {
endpoint: response.upload.upload_link, //this looks like vimeo.api.tus... something like that
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
}
}));
})
Then when that new tus upload is intiated it calls the Upload method in the Tus library which has http variables as below:
var xhr = (0, _request.newRequest)();
xhr.open("PATCH", this.options.endpoint, true);
xhr.setRequestHeader("Upload-Length", this._size);
xhr.setRequestHeader("Tus-Resumable", "1.0.0");
xhr.setRequestHeader("Upload-Offset", 0);
xhr.setRequestHeader("Content-Type", "application/offset+octet-stream")
xhr.onload = function () {
if (!inStatusCategory(xhr.status, 200)) {
_this2._emitXhrError(xhr, new Error("tus: unexpected response while creating upload"));
return;
}
var location = xhr.getResponseHeader("Location");
if (location == null) {
_this2._emitXhrError(xhr, new Error("tus: invalid or missing Location header"));
return;
}
xhr.send();
Now the issue is that this procedure is returning me an error as below:
Failed because: Error: tus: invalid or missing Location header, originated from request (response code: 204, response text: )
From the way i see it, this Location Header is supposed to be in the response from the request made. How do i go around this???