本文主要是介绍ruby on rails aliyun oss百度编辑器上传,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
html集成百度编辑器就很简单了,不过需要注意的是链接中,ruby on rails的链接默认action是操作名称,而百度编辑器也需要一个url参数action,所以需要把ueditor.all.min.js里面的get,post的action=改个名字,不如saction=
后台接收到图片,就用流式上传直接上传图片流,图片流上传查看:
https://blog.csdn.net/tang05709/article/details/88366824
def editor_upload res = nilact = params[:saction]case actwhen 'config'res = up_configwhen 'upload_image'upfile = params[:upfile]ext = File.extname(upfile.original_filename)file_name = Tools::GetRandString.date_rand_string(16) + extfile_key = 'details_upload/' + file_nameAliyun::AliyunOssAchieve.upload_by_io(file_key, upfile.read)url = Rails.configuration.application['ALIYUN_OSS_HOST'] + '/' + file_keyres = {"state": "SUCCESS","url": url,"title": file_name,"original": file_name,}when 'upload_video'res = {state: '不支持使用编辑器上传视频'}when 'catch_image'res = {state: '不支持使用编辑器上传视频'}elseres = {state: '请求错误'}endrender json: resenddef delete_imageAliyun::AliyunOssAchieve.delete_oss(params[:filename])render json: {'status': 'success'}endprivate def up_configconfig = {"imageActionName" => "upload_image", # 执行上传图片的act名称 "imageFieldName" => "upfile", # 提交的图片表单名称 "imageMaxSize" => 2048000, # 上传大小限制,单位B "imageAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".svg"], # 上传图片格式显示 "imageInsertAlign" => "none", # 插入的图片浮动方式 "imageUrlPrefix" => "", # 图片访问路径前缀 "catcherLocalDomain" => ["127.0.0.1", "localhost", "www.sonliss.com"],"catcherActionName" => "catch_image", # 执行抓取远程图片的action名称 "catcherFieldName" => "source", # 提交的图片列表表单名称"catcherUrlPrefix" => "", # 图片访问路径前缀 "catcherMaxSize" => 2048000, # 上传大小限制,单位B "catcherAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], # 抓取图片格式显示 "videoActionName" => "upload_video", # 执行上传视频的action名称 "videoFieldName" => "upfile", # 提交的视频表单名称 "videoUrlPrefix" => "", # 视频访问路径前缀 "videoMaxSize" => 102400000, # 上传大小限制,单位B,默认100MB "videoAllowFiles" => [".flv", ".3gp", ".mpeg", ".mp4"], # 上传视频格式显示 }end
这篇关于ruby on rails aliyun oss百度编辑器上传的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!