1

I am trying to upload a video file to vimeo using their resumable upload protocol, but end up getting

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

this error whenever I initiate the upload.

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

This is the code for the upload function. I also tried setting Content-Length as a custom header in the tus config but it claimed it was a forbidden header and didn't let me modify it

enter image description here

Any thoughts or advice on the matter will be much appreciated.

1 Answers1

1

The initial request to create the video is most likely malformed or invalid. For tus upload, the Vimeo API will return an upload_link on the files.tus.vimeo.com domain (or similar). Make sure the initial POST /me/videos request specifies upload.approach=tus.

Before attempting the actual file upload, you'll want to verify that the API returns upload.approach=tus.

The Vimeo API's tus docs are found here: https://developer.vimeo.com/api/upload/videos#resumable-approach

Tommy Penner
  • 2,440
  • 1
  • 7
  • 13