Trying to upload video to vimeo via API, resumable approach, getting 412 response

868 views Asked by At

I'm trying to upload a video via the presumable approach, I'm able to get the upload link through PHP curl and jQuery ajax then I'm trying to upload the file but I receive 412 error.

Failed because: Error: Tus: unable to resume upload (new upload cannot be created without an endpoint), originated from request (method: HEAD, URL: https://asia-files.tus.vimeo.com/files/vimeo-prod-src-tus-asia/123456789, response code: 412, response text: , request id: n/a) (123456789 is just a dummy number here)

I tried to remove the headers but I get 404 error which seems worse to me, so I kept the headers. I'm unable to upload the file via Postman (testing API software)which is also weird, PATCH with binary data in body, I get a response 204 that there is no content. When I try the HEAD request for the upload link via Postman (testing API software), I get status 200.

Expected behavior The file should have been uploaded to Vimeo in chunks...

Used Tus-JS-client version: [1.0.0] CDN: ttps://cdn.jsdelivr.net/npm/tus-js-client@latest/dist/tus.min.js

function resumable(url) {


    let file = $('#video')[0].files[0];
    var chunkSize = 128;
    // Create a new tus upload
    const upload = new tus.Upload(file, {
        uploadUrl: url,
        headers:{
            "Tus-Resumable":    "1.0.0",
            "Accept":   "application/vnd.vimeo.*+json;version=3.4"
        },
        //endpoint: url,
        chunkSize,
        retryDelays: [0, 3000, 5000, 10000, 20000],
        metadata: {
            filename: file.name,
            filetype: file.type,
        },
        uploadSize: file.size,
        onError(error) {
            console.log(`Failed because: ${error}`);
        },
        onProgress(bytesUploaded, bytesTotal) {
            const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2);
            console.log(bytesUploaded, bytesTotal, `${percentage}%`);
        },
        onSuccess() {
            console.log('Download %s from %s', upload.file.name, upload.url);
        },
})

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

  
1

There are 1 answers

1
user9852942 On

tus-js-client documentation has a Vimeo-specific example