简体   繁体   English

使用CKEditor,BLOB字段和Rails 4自定义上传图像

[英]Custom Upload Images using CKEditor, BLOB field and Rails 4

I'm currently using CKEditor in my site. 我目前在我的网站上使用CKEditor。 The user may upload some images to the server using the button for Upload Image in the CKEditor. 用户可以使用CKEditor中的“上传图像”按钮将一些图像上传到服务器。

There is a textarea field with id #article_conteudo on the page that uses the CKEditor, here is the javascript code to configure the editor: 在使用CKEditor的页面上,有一个id为#article_conteudo的textarea字段,这是用于配置编辑器的javascript代码:

CKEDITOR.replace('article_conteudo', {
    filebrowserImageUploadUrl: '/article/upload/'
});

The URL /article/upload/ points to a method file_upload in an articles_controller : URL / article / upload /指向articles_controller中的 file_upload方法:

def file_upload
    image = ArticlesImage.new

    image.imagem = params[:upload].read

    image.save
end

The images are stored in a BLOB field in a MySQL Database. 图像存储在MySQL数据库的BLOB字段中。

The images are saved in the database with no problems. 图像毫无问题地保存在数据库中。 But, after saving, nothing happens in the Editor. 但是,保存后,编辑器中什么也不会发生。 I'm not sure what is the expected response for the Upload Action of the CKEditor on this case. 我不确定在这种情况下对CKEditor的Upload Action的预期响应是什么。 I'm not sure, also, if CKEditor uploads support the use of BLOBs. 我也不确定CKEditor上传是否支持BLOB的使用。

How can I implement this functionality in my project? 如何在我的项目中实现此功能?

If it can't be done with CKEditor, is there any other plugin that can do it? 如果使用CKEditor无法完成此操作,是否还有其他插件可以执行此操作?

Thanks for your help 谢谢你的帮助

PS: The use of BLOB is MANDATORY for the project, I cannot use other methods PS:在项目中必须使用BLOB,我不能使用其他方法

it depends of what you need. 这取决于您的需求。

If you want to display images on your browser, you have to create the JSON response involved. 如果要在浏览器上显示图像,则必须创建涉及的JSON响应。

And then, the fileUploadResponse of the CKEditor would be able to display your images (or files) on your editor. 然后,CKEditor的fileUploadResponse将能够在编辑器上显示您的图像(或文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM