gpt4 book ai didi

ruby-on-rails - 用蜻蜓保存 TinyMCE Base64 图像

转载 作者:太空宇宙 更新时间:2023-11-03 16:30:09 25 4
gpt4 key购买 nike

我正在使用 tinymce-rails-imageupload蜻蜓插件。

当图像通过弹出窗口中的单独表单上传时,它的行为符合预期(将图像保存在数据存储中)。

但是当用户将图像拖放到或粘贴到 TinyMCE 中时,图像上传插件允许这样做。我试图找到一种方法来禁用此行为,但显然没有直接的方法来禁用允许图像上传,同时禁止过去/拖放行为。所以我放弃了..

现在,我正在尝试将 BASE64 图像保存在 TinyMCE 的内容中。

在 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

在资源模型中,我会有这样的东西:

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

问题:

  • 如何创建“Entry with file”?

  • 在使用 dragonfly 的 TinyMCE 中,是否有更好的方法来处理粘贴/拖放的 base64 图像?

最佳答案

关于ruby-on-rails - 用蜻蜓保存 TinyMCE Base64 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17549740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com