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异步格式返回等待

相关推荐
bugcome_com21 小时前
阿里云 OSS C# SDK 使用实践与参数详解
阿里云·c#
孤岛悬城1 天前
37 日志分析:ELK(Elasticsearch+Logstash+Kibana)
云计算
主机哥哥1 天前
阿里云OpenClaw部署全攻略,五种方案助你快速部署!
服务器·阿里云·负载均衡
珠海西格电力科技1 天前
微电网能量平衡理论的实现条件在不同场景下有哪些差异?
运维·服务器·网络·人工智能·云计算·智慧城市
Sheffield2 天前
command和shell模块到底区别在哪?
linux·云计算·ansible
Hello.Reader2 天前
Flink 对接阿里云 OSS(Object Storage Service)读写、Checkpoint、插件安装与配置模板
大数据·阿里云·flink
DolitD2 天前
云流技术深度剖析:国内云渲染主流技术与开源和海外厂商技术实测对比
功能测试·云原生·开源·云计算·实时云渲染
翼龙云_cloud2 天前
阿里云渠道商:阿里云 ECS 从安全组到云防火墙的实战防护指南
安全·阿里云·云计算
YongCheng_Liang2 天前
从零开始学虚拟化:桌面虚拟化(VDI)入门指南(架构 + 产品 + 部署)
运维·云计算
万物得其道者成2 天前
阿里云 H5 一键登录接入实战:前后端完整实现
阿里云·云计算·状态模式