2020-10-07 01:32:34

layuiAdmin中的layim上传图片使用阿里oss

pc端layim.js和手机端mobile.js文件中

下载aliossUploader放入controller中

region为阿里oss节点,bucket为存储

PC端搜索 image:function(i){ 下面代码放到后方

layui.use("aliossUploader",function(){var a=layui.aliossUploader,e=i.data("type")||"images",n=_();a.render({elm:i.find("input")[0],region:"oss-cn-hongkong",bucket:"xxxx",layerTitle:"上传图片",accessidFiled:"accessid",policyFiled:"policy",signatureFiled:"signature",policyData:{},policyHeader:{Authorization:"Bearer "+layui.data(layui.setter.tableName).Authorization},policyUrl:"/rg/rgaccount/getOss",fileType:"images",multiple:!1,httpStr:"http",prefixPath:"rgAccQrUrlDir/",allUploaded:function(i){console.log("上传响应",i),"images"===e?ai(n.textarea[0],"img["+(i[0].ossUrl||"")+"]"):"file"===e&&ai(n.textarea[0],"file("+(i[0].ossUrl||"")+")["+(i.data.name||"下载文件")+"]"),_()},policyFailed:function(i){t.msg(i.msg||"上传失败")}})})}

手机端搜索 image:function(i){ 下面代码放到后方

layui.use("aliossUploader",function(){var e=layui.aliossUploader,a=i.data("type")||"images",t=T();e.render({elm:i.find("input")[0],region:"oss-cn-hongkong",bucket:"xxxx",layerTitle:"上传图片",accessidFiled:"accessid",policyFiled:"policy",signatureFiled:"signature",policyData:{},policyUrl:"/rg/rgaccount/getOss",fileType:"images",multiple:!1,httpStr:"http",prefixPath:"rgAccQrUrlDir/",allUploaded:function(i){console.log("上传响应",i),"images"===a?P(t.textarea[0],"img["+(i[0].ossUrl||"")+"]"):"file"===a&&P(t.textarea[0],"file("+(i[0].ossUrl||"")+")["+(i[0].name||"下载文件")+"]"),I()},policyFailed:function(i){layer.msg(i.msg||"上传失败")}})})}

本文链接:https://zk1006.com/archives/17.html

评论