我正在开发使用卓越的Vimeo上传API的Adobe Air应用。上传工作非常好。
但是,我现在尝试恢复上传,并且无法理解它为什么不起作用。有人可以帮我理解为什么吗?
这是我在doc中提出的流程。代码是AS3:
验证上传
var r:URLRequest = new URLRequest(_ticket.upload_link_secure);
r.requestHeaders = [
new URLRequestHeader("Authorization", "bearer " + TOKEN),
new URLRequestHeader("Content-Length", "0"),
new URLRequestHeader("Content-Range", "bytes */*"),
];
r.contentType = "video/mp4"
r.method = URLRequestMethod.PUT;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, _resumeProgressComplete);
loader.load(r);
==> the result of the request :
status 308
the range header is bytes=0-474295
恢复上传
我的视频尺寸:11685783
ByteArray的大小发送:6533957
范围标题:5151826-11685783 / 11685783
内容长度:6533957(我也尝试过ByteArray大小+1,如文档所示)
var r:URLRequest = new URLRequest(_ticket.upload_link_secure);
r.requestHeaders = [
new URLRequestHeader("Authorization", "bearer " + TOKEN),
new URLRequestHeader("Content-Length", contentLength),
new URLRequestHeader("Content-Range", range),
];
r.contentType = "video/mp4"
r.method = URLRequestMethod.PUT;
r.data = ba;
_urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
_urlLoader.addEventListener(Event.COMPLETE, _resumeComplete);
_urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, _resumeHTTPStatus);
_urlLoader.load(r);
请求的结果状态为200
在上传我视频中缺失的部分时,我会异步发送请求以获取上传的进度
var r:URLRequest = new URLRequest(_ticket.upload_link_secure);
r.requestHeaders = [
new URLRequestHeader("Authorization", "bearer " + TOKEN),
new URLRequestHeader("Content-Length", "0"),
new URLRequestHeader("Content-Range", "bytes */*"),
];
r.contentType = "video/mp4"
r.method = URLRequestMethod.PUT;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, _uploadProgressComplete);
loader.load(r);
结果:
bytes=0-0
bytes=0-228970
bytes=0-441585
bytes=0-556070
...
bytes=0-6247610
bytes=0-6492935
bytes=0-6533957
上次验证完成后,我发送完成上传
var r:URLRequest = new URLRequest("https://api.vimeo.com/" + _ticket.complete_uri);
r.requestHeaders = [
new URLRequestHeader("Authorization", "bearer " + TOKEN)
];
r.method = URLRequestMethod.DELETE;
_urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, _completeUploadComplete);
_urlLoader.addEventListener(Event.COMPLETE, _completeUploadCompleteData);
_urlLoader.load(r);
以下是我收到400状态的错误消息:
{"错误":"您的视频文件无效。您上传的文件格式无效,或上传不完整。确保在将其标记为完成之前验证您的上传。"}
我的代码是否有问题,我按照文档进行了操作?
答案 0 :(得分:0)
感谢Upload a video file by chunks我可以看出我的错误在哪里:
new URLRequestHeader("Content-Range", "bytes " + range),
我只是忘记了标题值中的“字节”......
顺便说一下,我修改了我在下面问题的答案中所写的范围
这是结果
var range:String = String(firstByte) + "-" + String(_videoSize - 1) + "/" + String(_videoSize);
// envoi de la vidéo
var r:URLRequest = new URLRequest(_ticket.upload_link_secure);
r.requestHeaders = [
new URLRequestHeader("Authorization", "bearer " + TOKEN),
new URLRequestHeader("Content-Length", contentLength),
new URLRequestHeader("Content-Range", "bytes " + range),
];
r.contentType = "video/mp4"
r.method = URLRequestMethod.PUT;
r.data = ba;
_urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
_urlLoader.addEventListener(Event.COMPLETE, _resumeComplete);
_urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, _resumeHTTPStatus);
_urlLoader.load(r);
开心:)