首页 > 解决方案 > 如何使用 ckeditor 在 mongoose-node 应用程序中上传图像。文件将上传到 s3

问题描述

我正在使用 CKEditor 在猫鼬中上传内容。我希望图像与内容一起上传。我将图像存储到 s3 并且 mongodb 将图像路径存储在字符串中(当不使用 ckeditor 上传时)。

我正在尝试使用这个模块 https://github.com/mjadobson/ckeditor5-sss-upload

我正在尝试这段代码

构建-config.js

module.exports = {
  // ...

  plugins: [
    "@ckeditor/ckeditor5-essentials/src/essentials",
    // ...

    //'@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter',
    //'@ckeditor/ckeditor5-easy-image/src/easyimage',

    "ckeditor5-sss-upload/src/s3upload"

    // ...
  ],

  // ...

  config: {
    toolbar: {
      items: [
        "headings",
        "bold",
        "italic",
        "imageUpload",
        "link",
        "bulletedList",
        "numberedList",
        "blockQuote",
        "undo",
        "redo"
      ]
    }
    // ...
  }
};

研讨会.js

const build_config=require('../build-config');

router.get('/add',ensureAuthenticated,(req,res)=>{
  SeminarGamenameConf.find().then(gameName_list=>{
    SeminarGametypeConf.find().then(gameType_list=>{
      console.log(gameType_list);
      res.render('cms/seminar/add',{
        gameName_list_array:gameName_list,
        gameType_list_array:gameType_list,
        country: countries,
        build_config:build_config
      });
    })
  })
});

//add.handlebars

<script src="/ckeditor5-build-classic/ckeditor.js"></script>

<form action="/cms/seminar/add" enctype="multipart/form-data" method="post" >
<div class="form-group">
   <label for="seminar_detail">Seminar Details</label>
   <textarea class="form-control" id="editor1" name="seminar_detail</textarea>
   <input type="submit" value="submit"/>
</div>
</form>

<script>
ClassicEditor.create(document.querySelector("#editor"), {
  s3Upload: {
    policyUrl: "http://127.0.0.1/my-upload-endpoint",
    mapUrl: ({ location, bucket, key }) => {
      return location;
    }
  }
});
</script>

我真的很困惑。我不知道如何使用 ckeditor 将图像上传到 s3(在细节之间)。

请帮忙。如果有其他方法请回复

标签: node.jsexpressamazon-s3mongooseckeditor

解决方案


推荐阅读