SammyLin / redactor-rails

This repo is deprecated. Please check out official gem for Redactor 2. https://github.com/Redactor2/redactor2_rails
MIT License
390 stars 254 forks source link

Carrierwave + Amazon S3 uploader #122

Closed Jellyfishboy closed 9 years ago

Jellyfishboy commented 9 years ago

Hi all,

I've been trying to configure Redactor to upload pictures to my Amazon S3 bucket, via Carrierwave. It uploads images without any issues to the local directory in development, however, in production I don't have the issue to upload an image (only enter an external web link).

In the past, if Redactor doesn't show an upload option, it usually points to a lack of permissions for the upload directory target. Is there any kind of access configuration required for the Redactor uploader to work with Carrierwave and Amazon S3?

Here are my uploader and carrierwave configuration files:

https://github.com/Jellyfishboy/trado/blob/master/app/uploaders/redactor_rails_picture_uploader.rb

https://github.com/Jellyfishboy/trado/blob/master/config/initializers/carrierwave_config.rb

Thanks for any help. Tom

wilgoszpl commented 9 years ago

Few months passed from last update of this issue. @Jellyfishboy , please, tell me if you have solved that or if it wasn't just AWS configuration problem rather than gem bug.

If this issue is still present, I'll take a look on that.

wilgoszpl commented 9 years ago

I tested AWS S3 upload and it works. Your problem doesn't look like redactor-rails problem, rather carrierwave or fog configuration. Redactor uses carrierwave uploader for upload - if it works for local environment, it should be no differrence for aws if it is properly configured.

suramai commented 9 years ago

@wilgoszpl Could you please share how to integrate amazon S3 with redactor. I got both working in my app but i don't know how to integrate them. The example in redactor documentation has php as example. Could you please share how to do it in rails? Thanks.

swilgosz commented 9 years ago

If you have both working, so other images are uploaded to aws correctly. It means, the fog gem is configured properly.

I changed storage :file => storage :fog in my redactore_rails_picture_uploader.rb and did the same for documents.

class RedactorRailsPictureUploader < CarrierWave::Uploader::Base
  include RedactorRails::Backend::CarrierWave

  # Include RMagick or ImageScience support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick
  # include CarrierWave::ImageScience

  # Choose what kind of storage to use for this uploader:
  storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "system/redactor_assets/pictures/#{model.id}"
  end

And my fog.rb file looks like that:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',                        # required
    :aws_access_key_id      => ENV['AWS_ACCESS_KEY_ID'],                        # required
    :aws_secret_access_key  => ENV['AWS_SECRET_ACCESS_KEY'],                        # required
    :region                 => ENV['AWS_BUCKET_REGION']                  # optional, defaults to 'us-east-1'
  }
  config.fog_directory  = ENV['AWS_BUCKET_NAME']                          # required
end
suramai commented 9 years ago

@swilgosz Thank you very much. I never knew about those files. Changing storage :file => storage :fog solved everything. Thank you very much.