Paperclip Gem With Wasabi
    • 20 Jun 2024
    • 1 Minute to read
    • PDF

    Paperclip Gem With Wasabi

    • PDF

    Article summary

    How do I use Paperclip Gem with Wasabi?

    Paperclip is validated with Wasabi as per the documentation https://github.com/thoughtbot/redstone#storage.

    Paperclip supports wasabi using either the fog-aws gem, or the aws-sdk-s3 gem.

    Since aws-s3 is deprecated, we can use fog-aws to integrate Wasabi with Paperclip.

    Following is an example of the configuration that can be added to the gem file.

    gem 'fog-aws'
    
    # config/initializers/paperclip.rbrequire 
    'paperclip/media_type_spoof_detector' # over-ride laterst version of 
    paperclip on how they # try to detect spoofed file content. module 
    Paperclip class MediaTypeSpoofDetector def spoofed? false end end end 
    Paperclip::Attachment.default_options[:storage] = :fog 
    Paperclip::Attachment.default_options[:fog_directory] = 
    ENV['AWS_BUCKET']Paperclip::Attachment.default_options[:path] = 
    ENV['AWS_PATH']Paperclip::Attachment.default_options[:fog_host] = 
    ENV['AWS_HOST_URL']Paperclip::Attachment.default_options[:fog_public] = 
    true Paperclip::Attachment.default_options[:fog_credentials] = 
    {provider: 'AWS',aws_access_key_id: 
    ENV['AWS_ACCESS_KEY_ID'],aws_secret_access_key: 
    ENV['AWS_SECRET_ACCESS_KEY'],region: ENV['AWS_REGION'],host: 
    ENV['AWS_HOST'],persistent: true }