You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vimeo新手使用URL上传视频成功但文件损坏无法播放求助

Troubleshooting Vimeo Upload "Corrupted File" Error (Even After API Success)

Hey there, let's dig into this frustrating issue—you get a success response from the Vimeo API, but the video won't play and says it's corrupted. Based on the code snippet you shared and how Vimeo's upload flow works, here are the most likely fixes:

Common Causes & Fixes

1. Missing Critical Request Headers

Your current code sets Accept and Authorization, but it's missing headers Vimeo needs to properly process the file:

  • Content-Type: Must match the actual MIME type of your video (e.g., video/mp4, video/mov). Without this, Vimeo might misinterpret the file data.
  • Content-Length: Tells Vimeo the exact size of the file, so it can verify that the entire file was received. If this is missing, Vimeo might not detect partial uploads.

Add these headers before sending the request:

xhr.setRequestHeader('Content-Type', videoFile.type); // Replace videoFile with your actual File/Blob object
xhr.setRequestHeader('Content-Length', videoFile.size);

2. Not Sending the Actual File Data

Looking at your code, there's no xhr.send() call with the file content! This is probably the biggest issue. You need to pass the raw File/Blob object (or a FormData wrapper, if required) to send() so Vimeo receives the video data.

Example of fixing this:

// Assume you have a File object named videoFile from an input element
xhr.send(videoFile);

// Or if the API expects FormData (check Vimeo's docs for your upload endpoint)
const formData = new FormData();
formData.append('file', videoFile);
xhr.send(formData);

3. Skipping the Final Upload Confirmation Step

Vimeo's upload flow (especially for resumable uploads) requires a final step to trigger video processing:

  1. First, create a video entry via POST /me/videos to get an upload URL.
  2. Upload the file to that URL.
  3. Patch the video entry with status: "available" to tell Vimeo the upload is complete and it should start transcoding.

If you skip step 3, Vimeo will leave the video in an incomplete state, leading to the "corrupted file" error. Add a confirmation method like this:

me.prototype.confirmUpload = function(videoUri) {
  const xhr = new XMLHttpRequest();
  xhr.open('PATCH', `https://api.vimeo.com${videoUri}`, true);
  xhr.setRequestHeader('Accept', 'application/vnd.vimeo.*+json;version=3.4');
  xhr.setRequestHeader('Authorization', 'Bearer YOUR_ACCESS_TOKEN');
  xhr.setRequestHeader('Content-Type', 'application/json');

  xhr.send(JSON.stringify({ status: 'available' }));

  xhr.onload = () => {
    if (xhr.status >= 200 && xhr.status < 300) {
      console.log('Upload confirmed! Vimeo is processing your video.');
    } else {
      console.error('Failed to confirm upload:', xhr.statusText);
    }
  };
};

Call this method after a successful upload, using the uri from the upload response.

4. Verify Your Access Token Permissions

Make sure your Vimeo access token has the upload and edit scopes. Without these, even if the upload seems to succeed, Vimeo might not process the video properly.

5. Check the File Itself

Double-check that the video plays locally first. If the file is corrupted on your end, uploading it won't fix the issue!

Modified Full Code Example

Here's how your upload method should look with these fixes:

me.prototype.upload = function(videoFile) {
  const xhr = new XMLHttpRequest();
  xhr.open(this.httpMethod, this.url, true);

  // Add required headers
  xhr.setRequestHeader('Accept', 'application/vnd.vimeo.*+json;version=3.4');
  xhr.setRequestHeader('Authorization', 'Bearer YOUR_FULL_ACCESS_TOKEN');
  xhr.setRequestHeader('Content-Type', videoFile.type);
  xhr.setRequestHeader('Content-Length', videoFile.size);

  // Handle upload completion
  xhr.onload = function() {
    if (xhr.status >= 200 && xhr.status < 300) {
      const response = JSON.parse(xhr.responseText);
      console.log('Upload successful:', response);
      // Confirm upload to trigger processing
      this.confirmUpload(response.uri);
    } else {
      console.error('Upload failed:', xhr.statusText);
    }
  }.bind(this);

  xhr.onerror = () => console.error('Network error during upload');

  // Send the actual video file
  xhr.send(videoFile);
};

// Confirmation method as above
me.prototype.confirmUpload = function(videoUri) {
  const xhr = new XMLHttpRequest();
  xhr.open('PATCH', `https://api.vimeo.com${videoUri}`, true);
  xhr.setRequestHeader('Accept', 'application/vnd.vimeo.*+json;version=3.4');
  xhr.setRequestHeader('Authorization', 'Bearer YOUR_FULL_ACCESS_TOKEN');
  xhr.setRequestHeader('Content-Type', 'application/json');

  xhr.send(JSON.stringify({ status: 'available' }));

  xhr.onload = () => {
    if (xhr.status >= 200 && xhr.status < 300) {
      console.log('Upload confirmed! Video processing started.');
    } else {
      console.error('Confirmation failed:', xhr.statusText);
    }
  };
};

Give these fixes a try—most likely, missing the file data in send() or skipping the confirmation step is the root cause. Let me know if you run into more issues!

内容的提问来源于stack exchange,提问作者Karan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:57:38