Ruby on rails 使用dragonfly保存TinyMCE Base64图像
我正在使用蜻蜓插件 当图像通过弹出窗口中的单独表单上传时,其行为符合预期(将图像保存在数据存储中) 但当用户将图像拖放或粘贴到TinyMCE中时,imageupload插件允许这样做。我试图找到一种方法来禁用此行为,但显然没有直接的方法来禁用允许图像上载,同时禁用过去/拖放行为。所以我放弃了 现在,我试图在TinyMCE的内容中保存BASE64图像 在控制器中:Ruby on rails 使用dragonfly保存TinyMCE Base64图像,ruby-on-rails,ruby,dragonfly-gem,Ruby On Rails,Ruby,Dragonfly Gem,我正在使用蜻蜓插件 当图像通过弹出窗口中的单独表单上传时,其行为符合预期(将图像保存在数据存储中) 但当用户将图像拖放或粘贴到TinyMCE中时,imageupload插件允许这样做。我试图找到一种方法来禁用此行为,但显然没有直接的方法来禁用允许图像上载,同时禁用过去/拖放行为。所以我放弃了 现在,我试图在TinyMCE的内容中保存BASE64图像 在控制器中: def store_file @image = Resource.new :res_image => params[:fil
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
在资源模型中,我会有如下内容:
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
问题:
- 如何创建“带文件的条目”
- 在TinyMCE中使用dragonfly处理粘贴/拖动的base64图像是否有更好的方法