[英]Saving TinyMCE Base64 images with dragonfly
I am using tinymce-rails-imageupload
plugin with dragonfly. 我正在将tinymce-rails-imageupload
插件与tinymce-rails-imageupload
一起使用。
When the image is uploaded via separate form in popup window, it behaves as expected (save image in datastore). 在弹出窗口中通过单独的表单上传图像时,其行为符合预期(将图像保存在数据存储区中)。
But when the user drag-drop or paste image into TinyMCE, the imageupload plugin allows it. 但是,当用户将图像拖放或粘贴到TinyMCE中时,imageupload插件将允许它。 I tried to find a way to disable this behavior, but apparently there is no straightforward way to disable allowing image upload, while disallowing the past/drag-drop behavior. 我试图找到一种禁用此行为的方法,但是显然没有一种直接的方法可以禁用允许图像上载,同时禁止过去/拖放行为。 So I gave up on that.. 所以我放弃了。
Now, I'm trying to save BASE64 image in TinyMCE's content. 现在,我正在尝试在TinyMCE的内容中保存BASE64图像。
In controller: 在控制器中:
def store_file
@image = Resource.new :res_image => params[:file]
@image.save
render json: {
image: {
url: @image.res_image.remote_url
}
}, content_type: "text/html"
end
def create
@entry = Entry.new(params[:entry])
# iterate through tinyMCE field params[:entry][:message]
# if image tag is found
# if value of src tag starts with "data:"
# then replace it with the output of
# Resource.create_image_from_base64(extracted_base64_value)
# end if
# end if
# end iteration
begin
@entry.save!
flash[:success] = "Entry was successfully created."
redirect_to entries_path
rescue Mongoid::Errors::Validations => e
render :action => "new"
end
end
In Resource model, I would have something like: 在资源模型中,我会有类似以下内容:
image_accessor :res_image
field :res_image_uid, type: String
field :res_image_name, type: String
def create_image_from_base64(base_64_encoded_data)
file = File.open('temp.png', 'wb') do|f|
f.write(Base64.decode64(base_64_encoded_data))
end
resource = # create Resource with temp file
file.close
resource.res_image.remote_url
end
How to create "Entry with file"? 如何创建“带有文件的条目”?
Is there a better approach for handling pasted/dragged-droped base64 images in TinyMCE with dragonfly? 有没有更好的方法在蜻蜓中处理TinyMCE中粘贴/拖放的base64图像?
Even if it is an old question: 即使是一个老问题:
look at this: https://groups.google.com/forum/#!topic/dragonfly-users/xNWIwZf5-_Y 看看这个: https : //groups.google.com/forum/#!topic/dragonfly-users/xNWIwZf5-_Y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.