【问题标题】:Getting "Content length 0 too small" when trying to upload to vimeo using tus尝试使用 tus 上传到 vimeo 时出现“内容长度 0 太小”
【发布时间】:2021-05-11 02:48:19
【问题描述】:

我正在尝试使用他们的可恢复上传协议将视频文件上传到 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

每当我启动上传时都会出现此错误。

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

这是上传功能的代码。 我还尝试在 tus 配置中将 Content-Length 设置为自定义标头,但它声称这是一个禁止的标头并且不允许我修改它

任何关于此事的想法或建议将不胜感激。

【问题讨论】:

    标签: node.js vimeo vimeo-api tus resumablejs


    【解决方案1】:

    创建视频的初始请求很可能格式不正确或无效。对于 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

    【讨论】:

      猜你喜欢
      • 2021-04-11
      • 2023-03-05
      • 1970-01-01
      • 2019-02-26
      • 2020-07-13
      • 2018-11-22
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      相关资源
      最近更新 更多