当我使用 tus 将视频上传到 bunnystream 服务时,出现错误

问题描述 投票:0回答:1

我在bunnystream的API中看到了文档,用于使用TUS上传视频。 我复制了javascript示例,将数据更改为我自己的。 控制台给了我这个错误: 错误:tus:创建上传时出现意外响应,源自请求(方法:POST,url:https://video.bunnycdn.com/tusupload,响应代码:401,响应文本:,请求 ID:n/a)

我不知道为什么会这样,有人可以帮助我吗?

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()
    })
}

这就是我写的代码,我使用的是 tus 的 cdn,sha256。

javascript tus bunnycdn
1个回答
0
投票

我做到了!要启动 AccessKey 变量,您必须将其替换为您的 API 密钥。 “expiration_time”参数采用 UNIX 时间戳。我又添加了一天,我被以下页面引导:https://www.unixtimestamp.com

参数“libraryID”是您的图书馆的ID,因此您还可以从您的收藏中获取“collectionId”。不要忘记将您正在测试的位置设置为受信任的站点。

© www.soinside.com 2019 - 2024. All rights reserved.