jtescher / carrierwave-imageoptimizer

This gem allows you to simply optimize CarrierWave images via jpegoptim or optipng.
https://rubygems.org/gems/carrierwave-imageoptimizer
MIT License
212 stars 33 forks source link

No such file or directory #28

Closed bstarr322 closed 4 years ago

bstarr322 commented 7 years ago

Hello, I'm using this gem with aws, but I've got an issue as following:

/app/public/uploads/tmp/1497028822-4-0001-3567/promo320442409.jpeg 160x229 24bit N JFIF  [OK] 17565 --> 12804 bytes (27.11%), optimized.
No such file or directory @ rb_sysopen - uploads/medium/picture/3142-promo320442409.jpeg

Hosting: Heroku

Ruby & Rails Version:

ruby "2.4.0"
gem 'rails', '~> 5.0.1'

Gemfile.lock

carrierwave (0.11.2)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      json (>= 1.7)
      mime-types (>= 1.16)
      mimemagic (>= 0.3.0)
    carrierwave-aws (1.1.0)
      aws-sdk (~> 2.0)
      carrierwave (>= 0.7, < 2.0)
    carrierwave-base64 (2.5.0)
      carrierwave (>= 0.8.0)
      mime-types (~> 3.0)
    carrierwave-imageoptimizer (1.4.0)
      carrierwave (>= 0.8, < 2.0)
      image_optimizer (~> 1.6)
    carrierwave-mongoid (0.10.0)
      carrierwave (>= 0.8.0, < 0.12.0)
      mongoid (>= 3.0, < 7.0)
      mongoid-grid_fs (>= 1.3, < 3.0)

carrierwave.rb

CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = ENV.fetch('S3_BUCKET_NAME')
  config.aws_acl    = 'public-read'

  config.aws_attributes = {
    expires: 1.week.from_now.httpdate,
    cache_control: 'max-age=2592000'
  }

  config.aws_credentials = {
    access_key_id:     ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    region:            ENV.fetch('AWS_REGION') # Required
  }
  config.asset_host = "https://pageimages.n2me.tv"
end

picture_uploader.rb

class PictureUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  include CarrierWave::ImageOptimizer

  version :thumb, if: :large?
  if Rails.env.production?
    storage :aws
  else
    storage :file
  end

  # Prevent Removing Files
  def remove!
  end
  process optimize: [{ quality: 85 }]
  # Create different versions of your uploaded files:
  version :thumb do
    process resize_to_fill: [500, 750]
  end

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/"
  end

  def filename
    "#{model.id}-#{original_filename}" if original_filename
  end

  def present?
    model.image && model.image.sub("#{model.id}-", '').present?
  end

  private
  def large? picture
    image = MiniMagick::Image.open(picture.path)
    image[:width] > 500
  end

end

I'll appreciate you to advise me or find out the solutions.

Thank you

PS: I'm saving images as following:

m.remote_picture_url = "https://pageimages.n2me.tv/uploads/medium/picture/2817-promo320724086.jpeg"
m.save
jtescher commented 4 years ago

Closing due to inactivity