exif image rotation issue using carrierwave and rmagick to upload to s3

前端 未结 4 1667
自闭症患者
自闭症患者 2020-11-30 03:36

I\'ve got a photo upload feature in my rails app. The app uploads direct to s3 through carrierwave via rmagick and fog. The issue I am having is when a photo is uploaded via

4条回答
  •  心在旅途
    2020-11-30 03:56

    Well I got this working using fog instead or carrierwave_direct.

    Below is the code that ended up working for me:

    app/uploaders/image_uploader.rb

    class ImageUploader < CarrierWave::Uploader::Base
       include CarrierWave::MiniMagick
    
       include Sprockets::Helpers::RailsHelper
       include Sprockets::Helpers::IsolatedHelper
    
       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
        "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
      end
    
    
      def fix_exif_rotation #this is my attempted solution
        manipulate! do |img|
          img.tap(&:auto_orient)
        end
      end
    
      process :fix_exif_rotation
    end
    

    app/models/s3_image.rb

    class S3Image < ActiveRecord::Base
      attr_accessible :image, :name, :user_id, :image_cache
      mount_uploader :image, ImageUploader
    
      belongs_to :user
    end
    

    initializers/carrierwave.rb

    CarrierWave.configure do |config|
      config.fog_credentials = {
        provider: "AWS",
        aws_access_key_id: " ... ",
        aws_secret_access_key: " ... ",
        region: 'us-west-2'
      }
      config.fog_directory = " ... "
    end
    

提交回复
热议问题