2

我正在将图像/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);

}
4

1 回答 1

2

不幸的是,目前不支持 tus 协议。

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

如果这不可能,您的下一个最佳选择是使用可恢复上传。开发者文档中有关于如何执行此操作的指南。还有一个如何在 Python中执行此操作的示例(移植起来应该非常简单)。

于 2020-11-16T15:16:06.457 回答