上传至阿里云OSS

利用自己实现上传功能来实现阿里云OSS的上传

首先,安装 OSS 相关工具,然后编写代码:

// 具体值需要去阿里云控制台获取
let client = new OSS({
  // // region以杭州为例(oss-cn-hangzhou),其他region按实际情况填写。
  // region: '<Your region>',
  // // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
  // accessKeyId: '<Your AccessKeyId>',
  // accessKeySecret: '<Your AccessKeySecret>',
  // bucket: 'Your bucket name',
});

editor.config.customUploadImg = function (resultFiles, insertImgFn) {
    // resultFiles 是 input 中选中的文件列表
    // insertImgFn 是获取图片 url 后,插入到编辑器的方法
    client.put('myImg', resultFiles[0])
      .then(function (res) {
        // 上传图片,返回结果,将图片插入到编辑器中
        insertImgFn(res.url)
      }).catch(function (err) {
        console.log(err)
      })
}

更多配置请参考 阿里云官方文档

Copyright © wangEditor (2020 - present) all right reserved,powered by GitbookFile Modify: 2021-01-22 01:03:47

results matching ""

    No results matching ""