使用Cloudinary,Carrierwave,Ckeditor和Rails Admin时出现问题

问题描述 投票:0回答:3

我正在尝试使用Ckeditor和Rails Admin。我在哪里使用Carrierwave和云存储作为cloudinary。完成所有设置后,我可以看到CKeditor能够将文件保存在本地存储上,然后创建实际图像应存储的cloudinary网址。但问题是图像没有从该本地文件夹上传到cloudinary。我的简单文件上传工作正常的地方。没有任何问题。

我在这里遇到的另一个问题是 - 当我使用cloudinary时,存储名称应该是什么?至于文件和Amazon S3,我们将名称作为文件和s3

请回复

谢谢

ckeditor carrierwave rails-admin cloudinary
3个回答
3
投票

Cloudinary的Ruby GEM包含一个CarrierWave插件,供我们的许多客户使用。我们不知道Ckeditor的特殊问题(但我们还没有测试过)。

当您为CarrierWave使用Cloudinary的插件时,只需将include Cloudinary::CarrierWave添加到您的上传器类。它将Cloudinary定义为存储引擎和图像处理服务(两者都是基于云的)。只需在您的上传器类中注释掉storage :file行。所有图像都将直接上传到Cloudinary,所有转换后的版本都将使用Cloudinary URL生成。

请查看文档页面中的示例上传代码:http://cloudinary.com/documentation/rails_integration#carrierwave_upload

如果问题仍然存在,如果您可以共享上传代码,这将有所帮助,以便我们可以帮助确保正确定义。


1
投票

确保删除对CarrierWave.config.storage =:file的任何引用

如果上传不起作用,您需要执行以下几个操作:

在/config/initializers/carrierwave_init.rb中删除对以下内容的所有引用:

config.storage = :file

在您的上传器中删除和引用排序:

storage :file

1
投票

我也有ckeditor的问题。编辑你的CkeditorAttachmentFileUploader看起来像这样:

class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
  include Ckeditor::Backend::CarrierWave
  include Cloudinary::CarrierWave

  [:extract_content_type, :extract_size, :extract_dimensions].each do |method|
    define_method :"#{method}_with_cloudinary" do
      send(:"#{method}_without_cloudinary") if self.file.is_a?(CarrierWave::SanitizedFile)
      {}
    end
    alias_method :"#{method}_without_cloudinary", method
    alias_method method, :"#{method}_with_cloudinary"
  end

  def extension_white_list
    Ckeditor.attachment_file_types
  end
end

之后,您会发现另一个错误。我发现在Ckeditor::AssetResponse#asset_url方法中,asset对象没有被重新加载,所以asset.content_url将始终为nil因此导致错误。我这样修好了:

class Ckeditor::Picture < Ckeditor::Asset
  ...
  def url_content
    url(:content) || begin
      if persisted?
        reload
        url(:content)
      end
    end
  end
end

同样对于Ckeditor::AttachmentFile课程,如果你有它。

© www.soinside.com 2019 - 2024. All rights reserved.