0

所以我将视频文件上传到远程服务/服务器(Ooyala)。我很难弄清楚如何显示发送到服务器的文件块的进度。我已经让其他一切都运行良好,并且显示上传进度是我的用例所需的最后一件事。我非常不愿意更改我的代码,我认为这就是我没有得到它的原因。用户将文件上传到表单,我将其分成多个块,并使用 formData 附加它们。然后我的 $.ajax 将所有 formData 发送到我的服务器进行处理以上传到远程 Ooyala 服务器:

$.ajax({
    url: ".parseUploadJSON.php",
    data: formData,
    processData: false,
    contentType: false,
    type: "POST",
        success: function (result) {
          if($('.notice').length != 0){
         $('.notice').hide();
          }
        $("#progress").hide();
        $("#alert").html("Thank you for your submission! Your video will be reviewed shortly. Please check back soon at <a href='http://site.com/page/local-video-uploads'>Local Video Uploads</a> to see if your entry has been approved.");
    console.log(result);
        }
    }); //end $.ajax 

从那里我使用 Curl 将块发送到 Ooyala。无论如何,我可以更新发送到服务器的块的客户端吗?我的 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, false); 每次发送一个块时都会调用它。

foreach($upload_urls as $key => $url){

    $response_bool = curlOps($_FILES['fileChunk'.$key]['tmp_name'], $url);
    if($response_bool){
        $percentage += (1/sizeof($upload_urls)*100);
        $response_array['status'] = 'success';
        $response_array['progress'] = $percentage;
    }else {
        $response_array['status'] = 'error';
        $response_array['message'] = 'Something happened.  Please refresh the page and try again';
        break;
    }
}

我正在考虑使用它作为指示块已成功发送。不幸的是,我的 AJAX 仅在发送所有块后才返回响应。有没有办法使用这个 $.ajax 调用来做到这一点?

感谢您的时间

4

0 回答 0