【问题标题】:Upload large Video上传大视频
【发布时间】:2021-02-27 09:09:48
【问题描述】:

我正在将图像/pdf 上传到 S3Uploads 并将视频上传到 JwPlayer。它工作正常。现在我需要上传大视频,它可以是 10,20... GB。 问题是客户端不想更改 php.ini 或创建 .user.ini 或更改 .htaccess 文件以增加上传文件大小和帖子大小。

如何上传大视频。找到解决方案https://github.com/ankitpokhrel/tus-php 它还支持前端的UPPY,但我不知道如何将它实现到jwplatform 上传。请帮忙。

我正在使用的前端 - https://uppy.io/docs/xhr-upload/

<link href="<?=base_url(); ?>assets/uppy.min.css" rel="stylesheet">
<script src="<?=base_url(); ?>assets/uppy.min.js"></script>
<script>
    var uppy = Uppy.Core()
        .use(Uppy.Dashboard, {
        inline: true,
        formData:true,
        target: '#drag-drop-area'
    })
    .use(Uppy.XHRUpload, {endpoint: uploadUrl', method:'post'}) //you can put upload URL here, where you want to upload images
    .uppy.on('complete', (result) => {
        console.log('Upload complete! We’ve uploaded these files:', result.successful)
    });
</script>

后端 - https://github.com/jwplayer/jwplatform-php(用于视频上传)

    $cpt = count($_FILES['files']['name']);
    $thumb = NULL;
    $video_key = NULL;
    $uploadedImages = [];
    for($i=0; $i<$cpt; $i++)
    {
        $mime = $_FILES['files']['type'][$i];
        if(strstr($mime, "video/")){
        $filetype = "video";
        }else if(strstr($mime, "image/")){
        $filetype = "img";
        }else if(strstr($mime, "/pdf")){
            $filetype = "pdf";
        }else{
            $filetype = "";
        }
        if(!empty($_FILES['files']['name'][$i]) && !empty($filetype)){
            $path = "upload/media/";
            try {
                if ($filetype=='video'){
                    $video_path = $_FILES['files']['tmp_name'][$i];
                    if ($video_path) {
                        $params = array();
                        $params['title'] = $_FILES['files']['name'][$i];
                        $params['description'] = 'Not available';


                        $jwplatform_api = new Jwplayer\JwplatformAPI('aaaasdf', 'asdfasdfasdfasdf');

                        $create_response = json_encode($jwplatform_api->call('/videos/create', $params));

                        $decoded = json_decode(trim($create_response), TRUE);
                        $upload_link = $decoded['link'];
                        $upload_response = $jwplatform_api->upload($video_path, $upload_link);

                        $video_key = $upload_response['media']['key'];
                        $file_url = $video_path;
                    }
                }
                else{
                    $filename = time()."_".$_FILES['files']['name'][$i];
                    $file_url = s3UploadMultiple($_FILES['files']['tmp_name'][$i],$path,$filename);

                    if (!empty($file_url) && $filetype == "img"){
                        $thumb = thumbnail($account_id,$file_url,150,150,"/media/thumbnails/");
                    }else{
                        $thumb = $file_url;
                    }
                }
                $new = new Medialib;
                $new->account_id = $account_id;
                $new->file_url = $file_url;
                $new->file_thumb = $thumb;
                $new->file_type = $filetype;
                $new->video_key = $video_key;
                $new->title = $_FILES['files']['name'][$i];

                $new->save();

                $new = Medialib::find('last',array('conditions'=>array('account_id'=>$account_id,'file_url'=>$file_url)));

                array_push($uploadedImages,(object)["id"=>$new->id,"src"=>$new->file_url, "thumb" => $thumb]);
            } catch (Exception $e) {
                echo $e;
            }

        }
    }
    echo json_encode($uploadedImages);

}

【问题讨论】:

    标签: php codeigniter jwplayer uppy tus


    【解决方案1】:

    很遗憾,目前不支持 tus 协议。

    上传大文件的最佳方法是将其上传到中间位置(如 S3),然后通过将 download_url 设置为文件链接将文件导入 jwplatform。在example folder of jwplatform-php 中有一个如何执行此操作的示例。此方法支持最大 25 GB 的文件。

    如果这不可能,您的下一个最佳选择是使用可恢复上传。 developer docs 中提供了有关如何执行此操作的指南。还有一个例子说明如何做到这一点in Python(应该很容易移植)。

    【讨论】:

      猜你喜欢
      • 2014-07-04
      • 2015-08-19
      • 2014-03-10
      • 2017-02-26
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      相关资源
      最近更新 更多