2

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

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

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

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

在控制器中:

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 中粘贴/拖放的 base64 图像?

4

1 回答 1

1

即使这是一个老问题:

看看这个:https ://groups.google.com/forum/#!topic/dragonfly-users/xNWIwZf5-_Y

于 2015-03-22T01:57:43.753 回答