1 官方下載sdkios
2 在引入編輯器頁面。寫入jsjson
// 百度編輯器 UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl; UE.Editor.prototype.getActionUrl = function (action) { if (action == 'uploadimage' || action == 'uploadscrawl') { return "/alioss/file_upload_ueditor";//這就是自定義的上傳地址 } else if (action == 'uploadvideo') { return ''; } else { return this._bkGetActionUrl.call(this, action); } } var ue = UE.getEditor('article_content', { zIndex: 999, initialFrameWidth: "100%", //初化寬度 initialFrameHeight: 300, //初化高度 focus: false, //初始化時,是否讓編輯器得到焦點true或false maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//容許的最大字符數 'fullscreen', pasteplain: false, //是否默認爲純文本粘貼。false爲不使用純文本粘貼,true爲使用純文本粘貼 autoHeightEnabled: true });
其中 編輯器
/alioss/file_upload_ueditor
就是咱們自定義的上傳路徑,原理就是攔截百度原來的上傳請求,從而到達不修改百度sdk的狀況下。實現自定義接口,ide
返回格式要按照以下:this
/** * 百度編輯器上傳圖片 */ public function file_upload_ueditor(){ $file = request()->file(); if (!empty($file) && isset($file['upfile'])) { $alioss_model = model("AliossModel"); $upfile = $file['upfile']; $file_data = $upfile->getInfo(); $path = 'thumb'; $file_mes = $alioss_model->file_upload($file_data,$path); $img_host_url = Config::get("config_set.img_host_url"); $result = [ 'state' => 'SUCCESS', 'url' => $img_host_url.$file_mes['file_path'], 'title' => '圖片', 'original' => $file_mes['file_path'] ]; return json($result); }else{ return json([ 'state' => '文件上傳失敗' ]); } }