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

相关推荐
@业精于勤荒于嬉20 小时前
将图片存储至阿里云 OSS
前端·阿里云·云计算·oss
罗技12320 小时前
Easysearch 使用 AWS S3 进行快照备份与还原:完整指南及常见错误排查
linux·云计算·aws·es·easysearch
AWS官方合作商20 小时前
AWS AppStream 2.0:开启云端应用交付新范式(实战解决方案剖析)
系统架构·云计算·aws
Linux运维老纪1 天前
Python实战项目(‌Hands-on Python Project)
开发语言·数据库·python·sql·mysql·云计算·运维开发
晨曦启明7111 天前
Linux云计算SRE-第十八周
linux·运维·云计算
忙碌的菠萝2 天前
阿里云扩容操作步骤
阿里云·云计算
程序员王天2 天前
阿里云oss开发实践:大文件分片、断点续传、实时进度 React+Node+Socket.IO
前端·react.js·阿里云·node.js
广拓科技2 天前
阿里云QwQ-32B模型发布:AI领域的新突破
人工智能·阿里云·云计算
远方2.02 天前
阿里云操作系统(AliOS)
阿里云·云计算
EterNity_TiMe_2 天前
深度评测阿里云操作系统控制台:功能全面,体验卓越!
阿里云·云计算·产品评测·操作系统控制台