Vimeu 在 air 应用程序上恢复 PUT 上传问题

Vimeu resume PUT upload issue on air app

我正在开发一个使用出色的 Vimeo 上传 API 的 Adob​​e Air 应用程序。上传真的很好。

但是,我现在尝试恢复上传,但不明白为什么它不起作用。有人可以帮我理解为什么吗?

这是我在文档中提出的流程。代码是 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
发送字节数组的大小:6533957
范围 header : 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 状态和以下错误消息的地方:

{"error":"Your video file is not valid. Either you have uploaded an invalid file format, or your upload is incomplete. Make sure you verify your upload before marking it as complete."}

我的代码有什么问题吗,我按照文档做了?

感谢 Upload a video file by chunks 我可以看出我的错误在哪里 :

new URLRequestHeader("Content-Range", "bytes " + range),

我只是忘记了 header 值中的 "byte "...

顺便说一下,我修改了下面问题的答案中所写的范围

这是结果

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

快乐:)