【问题标题】:Ruby on Rails API + VueJS + CKEditor image upload to S3Ruby on Rails API + VueJS + CKEditor 图片上传到 S3
【发布时间】:2021-02-04 09:28:09
【问题描述】:

我的后端有一个Rails API,前端有一个Vue.JS 应用程序。 有一些功能允许用户将图像上传到 AWS S3(我将 Base64 图像发送到 API 并使用 Carrierwave 上传文件......它就像一个魅力!)

但现在我必须允许用户在CKEditor5 中写入文本并将图像插入正文。最好的方法是如何做到这一点?我正在考虑在 HTML 正文中发送 Base64 图像并在 API 中提取它们,但我正在寻找更好的方法/想法。

谢谢!

【问题讨论】:

    标签: ruby-on-rails vue.js amazon-s3 ckeditor carrierwave


    【解决方案1】:

    最后,我查看了 CKEditor 文档并找到了这个链接: https://ckeditor.com/docs/ckeditor5/latest/features/image-upload/simple-upload-adapter.html

    所以我意识到有一个 uploadUrl 参数来设置我的后端端点,它应该只返回 de AWS S3 url 以神奇地在文本正文中替换,瞧!

            simpleUpload: {
                // The URL that the images are uploaded to.
                uploadUrl: 'http://example.com',
    
                // Enable the XMLHttpRequest.withCredentials property.
                withCredentials: true,
    
                // Headers sent along with the XMLHttpRequest to the upload server.
                headers: {
                    'X-CSRF-TOKEN': 'CSRF-Token',
                    Authorization: 'Bearer <JSON Web Token>'
                }
            }
    

    我在想一个完全疯狂的解决方案,而不是正确阅读文档!

    【讨论】:

      猜你喜欢
      • 2010-12-23
      • 2013-12-20
      • 1970-01-01
      • 2019-07-13
      • 2018-02-05
      • 2016-11-12
      • 1970-01-01
      • 2011-05-07
      • 2015-12-15
      相关资源
      最近更新 更多