首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试使用tus上传到vimeo时遇到"Content length 0 too small“问题

尝试使用tus上传到vimeo时遇到"Content length 0 too small“问题
EN

Stack Overflow用户
提问于 2021-02-07 15:51:45
回答 1查看 153关注 0票数 1

我正在尝试使用他们的可恢复上传协议将视频文件上传到vimeo,但最终得到

Failed because: Error: tus: unexpected response while creating upload, originated from request (method: POST, url: https://1515143405.cloud.vimeo.com/upload?ticket_id=42606237…62378%26signature%3D19062b29129850403638ca88040debe1e21cc646, response code: 400, response text: Content length 0 too small

每次我开始上传的时候都会出现这个错误。

代码语言:javascript
复制
const vimeoFileUpload = async(e) => {
const fileContent = e.target.files[0];
const fileSize = fileContent.size;
const reader = new FileReader();
reader.onload = r => {console.log(r.target.result)};
let uploadLink;

await fetch(`${backendUri}/fetchUploadLink`, {
    method: 'POST',
    body: JSON.stringify({fileSize}),
    headers: {"Content-Type": "application/json"}
}).then((res) => res.json())
   .then((result) => {
       uploadLink=result.uploadLink
   });

let uploader = new tus.Upload(fileContent, {
    uploadUrl: uploadLink,
    endpoint:uploadLink,
    retryDelays: [0, 1000, 3000, 5000],
    metadata: {
        filename: "sample",
        filetype: fileContent.type
    },
    uploadSize: fileSize,
    onError: function(error) {
        console.log("Failed because: " + error);
    },
    onProgress: function(bytesUploaded, bytesTotal) {
        let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
        console.log(bytesUploaded, bytesTotal, percentage + "%");
    },
    onSuccess: function() {
        console.log(
            "Download %s from %s",
            uploader.file.name,
            uploader.url
        );
    }
});
uploader.start();
}

这是upload函数的代码。我还尝试将Content-Length设置为tus配置中的自定义标头,但它声称这是一个禁止的标头,不让我修改它

对这件事的任何想法或建议都将非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2021-02-09 01:10:45

创建视频的初始请求很可能是错误的或无效的。对于tus上传,Vimeo API将在files.tus.vimeo.com域(或类似域)上返回一个upload_link。确保初始POST /me/videos请求指定upload.approach=tus

在尝试实际的文件上传之前,您需要验证API是否返回upload.approach=tus

Vimeo API的tus文档可以在这里找到:https://developer.vimeo.com/api/upload/videos#resumable-approach

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66085665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档