Reputation: 146
I am uploading images/pdf to S3Uploads and video to JwPlayer. it is working fine. Now I need to upload large video it can be 10,20... GB. problem is Client do not want to change php.ini or create .user.ini or change .htaccess file to increase upload file size and post size.
how do I upload large video. found solution https://github.com/ankitpokhrel/tus-php it also support UPPY for front end but I don't have any idea how it can be implemented to jwplatform upload. Please Help.
front-end I am using - 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>
backend - https://github.com/jwplayer/jwplatform-php (for video upload)
$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);
}
Upvotes: 2
Views: 532
Reputation: 1339
Unfortunately the tus protocol is not supported at this time.
The best way to upload a large file would be to upload it to a intermediate location (like S3) and import the file into jwplatform by setting download_url
to a link to the file. There is an example of how to do this in the example folder of jwplatform-php
. This method supports files up to 25 GB.
If this is not possible, your next best option is to use a resumable upload. There is a guide on how to do this in the developer docs. There is also an example of how to do this in Python (which should be pretty straightforward to port).
Upvotes: 2