我正在尝试在网站上实现一个上传模块,该模块允许我们的用户将视频上传到我们的 Vimeo 帐户。我正在使用 blueimp 的 jQuery 文件上传和 Vimeo 的新 API。https://github.com/blueimp/jQuery-File-Upload/wiki/Options https://github.com/blueimp/jQuery-File-Upload/wiki/Options
https://developer.vimeo.com/api/upload#http-put-uploading https://developer.vimeo.com/api/upload#http-put-uploading我认为它即将开始工作,但我一定错过了一些细节。
根据 Vimeo 的 API,我需要:
1.生成上传票,效果很好
2.然后我将 upload_link_secure 传递给 jquery 文件上传,开始上传。 PUT 请求的请求标头如下所示:
Request Method:PUT
Status Code:200 OK
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:43418955
Content-Type:multipart/form-data; boundary=----WebKitFormBoundarye8sGy57JH6ACoOfJ
这就是我调用 jQuery 文件上传的方式:
$('#file').fileupload({
url: upload_link_secure,
type: 'PUT'
});
我还尝试将 Content-Type 标头强制设置为“video/mp4”,但最终没有任何区别。
我还通过绑定 jquery fileupload 的提交事件检查了文件的大小,并且我还得到了比标头中发送的字节数更低的字节数,在本例中为 43418764,这样可以吗?
- 通过在 upload_link_secure 上发送 PUT 请求来验证上传,我得到了一些响应标头:
状态代码:308 简历不完整
范围:字节=0-3948544
状态代码:308 简历不完整
范围:字节=0-38682624
状态代码:308 简历不完整
范围:字节=0-43401216
- 确保所有字节均已发送至 Vimeo,然后通过在complete_uri 上发送 DELETE 请求来完成上传
验证上传时我得到最后一个标头:
范围:字节=0-43418955
它似乎与第一个请求中发送的内容长度匹配,因此我执行了 DELETE 请求,这是我得到的响应:
{"body":{"error":"您的视频文件无效。您上传的文件格式无效,或者上传不完整。请务必先验证您的上传,然后再将其标记为完成。"},"status ":400,"headers":{"日期":"2014 年 10 月 6 日星期一 17","服务器":"Apache","Vary":"接受、Vimeo-Client-Id、接受编码","缓存-Control":"无缓存,max-age=315360000","过期":"2024 年 10 月 3 日星期四 17","Content-Length":"184","X-Connection":"关闭","内容类型":"application/vnd.vimeo.error+json","通过":"1.1 dca1-10"}}
我一定犯了一个非常愚蠢的错误,但我不太熟悉所有这些 HTTP 请求和响应,有人知道我做错了什么吗?
Thanks !
[edit]非常感谢 Dashron,我实际上必须将 jQuery fileupload 的 multipart 选项设置为 false :
$('#file').fileupload({
url: upload_link_secure,
type: 'PUT',
multipart: false
});
之后,我收到此 HTTP 错误:
XMLHttpRequest cannot load https://1511632921.cloud.vimeo.com/upload?[...]. Request header field Content-Disposition is not allowed by Access-Control-Allow-Headers.
There might be a clean fix for that but I didn't find it so I simply commented the lines that set the Content-Disposition header in jquery.fileupload.js
// if (!multipart || options.blob || !this._isInstanceOf('File', file)) {
// options.headers['Content-Disposition'] = 'attachment; filename="' +
// encodeURI(file.name) + '"';
// }