Egg.js中富文本编辑器wysiwyg-editor配置上传图片的地址

发布于 1周前 作者 sinazl 最后一次编辑是 5天前 来自 分享

https://www.froala.com/wysiwyg-editor/docs/options#imageUploadURL


$(function() {
      $('#content').froalaEditor({
        height: 300,   
        imageUploadURL: '/admin/goods/uploadImg',
        language: 'zh_cn'        
      })
});

后台返回数据格式:{link: ‘path/to/image.jpg’}


async uploadImg() {
        let parts = this.ctx.multipart({ autoFields: true });
        let files = {};               
        let stream;
        while ((stream = await parts()) != null) {
            if (!stream.filename) {          
              break;
            }       
            let fieldname = stream.fieldname;  //file表单的名字

            //上传图片的目录
            let dir=await this.service.tools.getUploadFile(stream.filename);
            let target = dir.uploadDir;
            let writeStream = fs.createWriteStream(target);

            await pump(stream, writeStream);  

            files=Object.assign(files,{
              [fieldname]:dir.saveDir    
            })
            
        }      

      this.ctx.body={link: files.file};
}
1 回复

wysiwyg-editor 支持 PHP, Node.JS, .NET, Java, and Python vue react angular里面都可以用 不错不错

回到顶部