我正在尝试将 Vimeo PHP 库 (http://github.com/vimeo/vimeo-php-lib/blob/master/vimeo.php) 与 BlueImp 的 jQuery 文件上传器 (https://github.com/ blueimp/jQuery-文件上传)。我的问题是在上传过程中收到进度事件,这可能吗?这是我上传的临时页面(视频上传是临时硬编码的)
<?php if($_SESSION['ticket']){
//check upload status
}
?>
<button id="btn">Upload to vimeo</button>
<div id="status"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$('#btn').click(function(){
//alert('clicked');
$('#status').html('working...'); //this will continue in the background, need to set a session variable so the same file isn't uploaded twice. but how to get response? check ticket ID which should also be part of the session variable
$.ajax({
url: 'vimeo/upload.php',
data: { file: '13TimberAlley.mov'}
}).done(function(data){
alert('done');
var obj = jQuery.parseJSON(data);
$('#status').html( obj.video_id != undefined ? 'http://vimeo.com/'+obj.video_id:$('#status').html() );
$('#status').html( obj.error != undefined || obj.message != undefined ? obj.error+' '+obj.message:$('#status').html() )
clearInterval(status);
});
status = setInterval(checkUpload,1000);
function checkUpload() {
//alert('check: reload this page to get session vars?');
}
});
</script>
Vimeo 上传 API (https://developer.vimeo.com/apis/advanced/upload) 声明我可以通过流式传输 (https://developer.vimeo.com/apis/advanced/upload) 检查上传状态#streaming-step4)或发布(https://developer.vimeo.com/apis/advanced/upload#post-step4)
我可以看到 vimeo api 使用 post 方法,但我的问题是何时/何处将进度返回给浏览器。如果我使用上面的方法(setInterval),那么我不知道如何从初始 ajax 调用到 checkUpload javascript 函数中获取票证 ID 和/或端点。我想我可以通过 PHP 中的会话变量来做到这一点,但我无法让页面重新加载(以显示远程文件中设置的会话变量),直到上传完成
我在第 413 行附近修改了“vimeo.php”,内容如下:
//store ticket id to session variable so we can check upload status, or resume progress indicator if page is reloaded (doesn't work if browser is closed)
session_start();
$_SESSION['ticket']=$ticket;
$_SESSION['endpoint']=$endpoint;
在第 500 行附近,有以下内容:
// Confirmation successful, return video id
if ($complete->stat == 'ok') {
//upload was successful, we do not need to store this variable to check progress anymore
unset($_SESSION['ticket']);
unset($_SESSION['endpoint']);
$_SESSION['last_upload'] = 'http://vimeo.com/'.$complete->ticket->video_id;
return $complete->ticket->video_id;
}
有任何想法吗?