fastadmin框架同时使用 阿里云oss和阿里云点播

背景

项目的实际需求中既要用到阿里云oss产品又用到阿里云点播系统,实现完美的统一。设置两个地址downUrl,thirdCode。分别代表阿里云oss上传路径和阿里云点播系统vId。

实现

默认框架你已经集成好阿里云oss集成工作,前端html页面实现

复制代码
<form id="edit-form" class="form-horizontal form-ajax" role="form" data-toggle="validator" method="POST" action="">
    <input  name="row[id]" type="hidden" value="{$row.id}" >
    <div class="form-group" style="display: none">
        <label for="c-title" class="control-label col-xs-12 col-sm-2">{:__('作者')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-title" data-rule="" class="form-control" name="row[author]" type="text" value="{$row.author|htmlentities}" placeholder="请输作者">

        </div>
    </div>
    <div class="form-group">
        <label  class="control-label col-xs-12 col-sm-2">{:__('音视频')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-downurl" data-rule="" class="form-control" size="255" name="row[downurl]" type="text" value="{$row.downurl}">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="plupload-downurl" class="btn btn-danger plupload" data-input-id="c-downurl" data-mimetype="*" data-multiple="false" data-preview-id="p-downurl"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-downurl" class="btn btn-primary fachoose" data-input-id="c-downurl" data-mimetype="*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-downurl"></span>
            </div>
            <ul class="row list-inline plupload-preview" id="p-downurl"></ul>
        </div>
    </div>

    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed" id="submit">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>

table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                showToggle: false,
                showColumns: false,
                showExport: false,
                //commonSearch: false,
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                         {checkbox: true},
                         {field: 'id', title: __('序号'),operate:false},
                         {field: 'category.name', title: __('格式'),operate:false,formatter:Table.api.formatter.label},
						 {field: 'categoryId', title: __('格式'),visible: false,searchList: $.getJSON("ajax/filecate")},
                         {
                             field: 'title',
                             title: __('标题'),
                             operate:'LIKE',
                             cellStyle: {css: {"max-width": "500px","white-space":"nowrap","overflow":"hidden","text-overflow":"ellipsis"}}
                         },
                         {field: 'secondId', title: __('分类'), visible: false,searchList: $.getJSON("ajax/schooldata")},
						 {field: 'thumb', title: __('缩略图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                         {field: 'third_code', title: __('三方平台'),operate: false},
						 {field: 'createtime', title: __('提交时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},                         
                         {field: 'updatetime', title: __('更新时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},                         
                         {field: 'status', title: __('Status'), formatter: Controller.api.formatter.station, searchList: {0: __('草稿'), 1: __('发布')}},
                         {field: 'operate', title: __('Operate'), 
						     buttons: [
                                 {
                                     name: '视频转码',
                                     text: '',
                                     title: __('转码'),
                                     classname: 'btn btn-xs btn-success  btn-view btn-dialog',
                                     icon: 'fa fa-trademark',
                                     url: 'school/data/transfer?id={ids}',
                                     refresh:true ,
                                     visible: function (row) {
                                         //返回true时按钮显示,返回false隐藏
                                         if(row.categoryId===232){
                                             if(row.third_plat==0||!row.third_plat) return true;
                                         }
                                         return false
                                     }
                                 },
                                 {
                                     name: 'detail',
                                     text: '', title: '编辑',
                                     icon: 'fa fa-pencil',
                                     classname: 'btn btn-xs btn-info btn-addtabs',
                                     url: 'school/data/edit'
                                 }
                             ],						
						     table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

使用ajax异常实现上传

复制代码
public function uploadV(){
        Config::set('default_return_type', 'json');
     
        $attachment = null;
        $res="";
        //默认普通上传文件
        $file = $this->request->post('url');
        //print_r($file->getMime());
        //print_r($file->getFilename());
        //print_r($file->getRealPath());
        require_once APP_PATH. DIRECTORY_SEPARATOR . 'voduploadsdk' . DIRECTORY_SEPARATOR . 'Autoloader.php';
        try {
             //$upload = new Upload($file);
             //print_r($upload->getFile());
             //$attachment = $upload->upload();
             $apiRegionId = 'cn-beijing';
             $uploader = new \AliyunVodUploader(Config::get('aliVod.accessKeyId'), Config::get('aliVod.accessKeySecret'), $apiRegionId);
             $fileURL="http://xxxxxx".$file;
             $uploadVideoRequest = new \UploadVideoRequest($fileURL, "课程");
             $res = $uploader->uploadWebVideo($uploadVideoRequest);
            if ($res) { // 根据你的逻辑,可能需要检查 $res 是否表示成功
                return json(['status' => 'success', 'data' => $res]);
               
            } else {
                // 处理 $res 为空或失败的情况
                return json(['status' => 'error', 'message' => '上传失败,未获取到有效响应']);
               
            }
        } catch (\Exception $e) {
           
            return json(['status' => 'error', 'message' => $e->getMessage()]);
            
        }
        
    }

可以完美完成。本功能实现大概用了一周,遇到很多问题,包括sdk引入层级问题,ajax异步格式返回等待

相关推荐
BOB-wangbaohai2 小时前
阿里云ACP云计算备考笔记 (3)——云服务器ECS
阿里云·云计算·安全组·ecs·云盘
壬戌知秋2 小时前
yum更换阿里云的镜像源
阿里云·云计算
国际云,接待15 小时前
阿里云无影云桌面深度测评
运维·服务器·阿里云·云原生·云计算
arui216 小时前
Docker部署与应用、指令
阿里云·docker·容器
m0_694845571 天前
云服务器如何连接和远程操作?
linux·运维·服务器·安全·云计算
义达1 天前
Anycast从原理到实践
后端·架构·云计算
Johny_Zhao1 天前
Linux服务器(CentOS/Ubuntu)接口Bond模式详解、配置指南及交换机对应接口的配置示例
linux·网络安全·信息安全·云计算·shell·cisco·huawei·系统运维·华三
王道长服务器 | AWS1 天前
AWS VPC 网络详解:理解云上专属内网的关键要素
网络·云计算·aws
王道长服务器 | AWS1 天前
EC2 实例详解:AWS 的云服务器怎么玩?☁️
服务器·云计算·aws
国际云,接待2 天前
阿里云国际站,如何通过代理商邀请的链接注册账号
运维·服务器·科技·阿里云·云计算