Laravel框架实现点播上传阿里云功能
程序员文章站
2022-06-15 15:44:40
1、确认框架中安装了第三方alibabacoud控件实现代码如下上传过程中遇到任务问题,可以进行留言
1、确认框架中安装了第三方alibabacoud控件
实现代码如下
上传过程中遇到任务问题,可以进行留言
<?php namespace app\api\xxxx\controllers; use db; use illuminate\http\request; use alibabacloud\tea\utils\utils; use alibabacloud\sdk\vod\v20170321\vod; use alibabacloud\sdk\vod\v20170321\models\deleteimagerequest; use alibabacloud\sdk\vod\v20170321\models\getplayinforequest; use alibabacloud\sdk\vod\v20170321\models\deletevideorequest; use alibabacloud\sdk\vod\v20170321\models\getimageinforequest; use alibabacloud\sdk\vod\v20170321\models\createuploadvideorequest; use alibabacloud\sdk\vod\v20170321\models\createuploadimagerequest; use darabonba\openapi\models\config; use oss\ossclient; use alibabacloud\tea\tea; class commoncontroller extends xxcontroller { //视频点播上传 public function uploadvideo($filename,$title) { $title = explode('.',$param['title']); $filename = $param['filename']; if($title[1] == 'mp4') { $cateid = 3479;//分类id,阿里云点播可以设置 } $client = self::createclient("xxx", "xxx");//根据申请的值放入 $createuploadvideorequest = new createuploadvideorequest([ 'action' => 'createuploadvideo',//请求的上传函数 "filename" => $filename,//文件名称 "cateid" => $cateid,//类型名称 'title' => $param['title'],//标题 ]); $createres = $client->createuploadvideo($createuploadvideorequest); $videoid = $createres->body->videoid; //获取视频播放地址需要的参数 $formats = $title[1]; //base64解码 $uploadaddress = json_decode(base64_decode($createres->body->uploadaddress), true); $uploadauth = json_decode(base64_decode($createres->body->uploadauth), true); // 使用uploadauth和uploadaddress初始化oss客户端 $ossclient = $this->init_oss_client($uploadauth, $uploadaddress); $localfile = $filename; // 需要上传到vod的本地视频文件的完整路径 改这个有效果 // 上传文件,注意是同步上传会阻塞等待,耗时与文件大小和网络上行带宽有关 $result = $this->upload_local_file($ossclient, $uploadaddress, $localfile); //$result = multipart_upload_file($ossclient, $uploadaddress, $localfile); $arr = $this->playinfo($videoid,$formats); $data = utils::toarray(tea::merge($arr->body)); $brr = array(); $brr['videoid'] = $data['videobase']['videoid'];//视频id $brr['playurl'] = $data['playinfolist']['playinfo'][0]['playurl'];//返回的播放地址 return $brr; } public function init_oss_client($uploadauth, $uploadaddress) { $ossclient = new ossclient($uploadauth['accesskeyid'], $uploadauth['accesskeysecret'], $uploadaddress['endpoint'], false, $uploadauth['securitytoken']); $ossclient->settimeout(86400*7); // 设置请求超时时间,单位秒,默认是5184000秒, 建议不要设置太小,如果上传文件很大,消耗的时间会比较长 $ossclient->setconnecttimeout(10); // 设置连接超时时间,单位秒,默认是10秒 return $ossclient; } }
到此这篇关于laravel框架实现点播上传阿里云功能的文章就介绍到这了,更多相关laravel点播上传阿里云内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!