I saw the documentation in bunnystream's API, for uploading videos using TUS. I copied the javascript example, changed the data to my own. And the console gives me this error: Error: tus: unexpected response while creating upload, originated from request (method: POST, url: https://video.bunnycdn.com/tusupload, response code: 401, response text: , request id: n/a)
I don't know why that happens, so can anyone help me?
function UploadVideo(file, json, collectionId, libraryID){
const presigned_signature = sha256(libraryID + AccessKey + 1234567890 + json.guid);
// Create a new tus upload
var upload = new tus.Upload(file, {
endpoint: "https://video.bunnycdn.com/tusupload",
retryDelays: [0, 3000, 5000, 10000, 20000, 60000, 60000],
headers: {
AuthorizationSignature: presigned_signature, // SHA256 signature (library_id + api_key + expiration_time + video_id)
AuthorizationExpire: 1234567890, // Expiration time as in the signature,
VideoId: json.guid, // The guid of a previously created video object through the Create Video API call
LibraryId: libraryID,
},
metadata: {
filetype: file.type,
title: 'Video 4st Test from JS',
collection: collectionId
},
onError: function (error) { console.log(error)},
onProgress: function (bytesUploaded, bytesTotal) {
var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
progressBar.style.width = percentage + "%";
console.log(bytesUploaded, bytesTotal, percentage + "%");
},
onSuccess: () => {console.log('file uploaded successfully!')}
})
// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.
if (previousUploads.length) {
upload.resumeFromPreviousUpload(previousUploads[0])
}
// Start the upload
upload.start()
})
}
Thats the code I wrote, I'm using cdn for tus, sha256.
I did it! To start your AccessKey variable you must replace it with your API key. The "expiration_time" parameter is in UNIX timestamp. I added one more day, I was guided by the following page: https://www.unixtimestamp.com
The parameter "libraryID" is the id of your library, so you also take "collectionId" from your collection. Don't forget to set the place where you are testing as a trusted site.