0

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.

  • 401 means unauthenticated. This is clearly an issue with authentication / authorization. Check your AccessKey – Rode093 Jun 20 '23 at 22:16
  • Okay, I will check – Mohamed Amr Jun 20 '23 at 22:17
  • I checked the AccessKey and its right, but still don't work – Mohamed Amr Jun 20 '23 at 22:19
  • 1
    I've encountered the same issue, and my problem was that the expiration time was incorrect. The Bunny.net documentation is quite lacking in this regard, but it seems you haven't set the timestamp to a date in the future. In the code you share it's 1234567890, but it should be some time in the future. We don't know what timezone Bunny.net uses though, so I've had to set mine to 24 hours in the future and then my issue was solved. Good luck! – Jose Salvatierra Jul 10 '23 at 10:45

0 Answers0