Laravel框架实现点播上传阿里云功能
作者:xi_weina 时间:2023-06-13 20:13:30
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;
}
}
来源:https://blog.csdn.net/xi_weina/article/details/120550922
标签:Laravel,点播,上传,阿里云
0
投稿
猜你喜欢
Python第三方库undetected_chromedriver的使用
2022-12-06 14:29:27
python输出决策树图形的例子
2022-02-07 09:14:54
用FSO操作 xml
2008-09-03 12:26:00
vue中Npm run build 根据环境传递参数方法来打包不同域名
2024-04-27 16:17:22
Golang解析JSON遇到的坑及解决方法
2024-05-10 13:58:29
对Python的交互模式和直接运行.py文件的区别详解
2023-12-18 00:03:55
python编写的最短路径算法
2021-01-15 20:54:14
python使用xlsxwriter实现有向无环图到Excel的转换
2022-01-24 06:42:54
NumPy-ndarray 的数据类型用法说明
2023-07-09 22:01:40
Python趣味挑战之教你用pygame画进度条
2022-08-13 15:02:49
用javascript实现的仿Flash广告图片轮换效果
2024-04-19 09:59:29
Python字典的基础操作
2023-02-27 06:25:18
Tensorflow tf.nn.atrous_conv2d如何实现空洞卷积的
2023-03-29 11:05:43
javascript使用call调用微信API
2023-07-02 05:19:48
想用户所想(感受亚马逊的设计)
2007-08-26 17:09:00
Python入门教程 超详细1小时学会Python
2023-06-13 23:34:12
PHP PDOStatement::bindColumn讲解
2023-06-10 04:35:55
善用用户反馈——浅谈用户反馈数据的处理
2010-07-09 16:58:00
100 个 Python 小例子(练习题二)
2021-02-09 10:15:31
jQuery ajaxSubmit 实现ajax提交表单局部刷新
2024-05-02 17:05:35