lardawge/carrierwave_backgrounder

Errno::ENOENT: No such file or directory @ rb_sysopen

Closed this issue · 5 comments

Hello, I want to use Carrierwave Backgrounder on my project. Here is my configuration:

carrierwave.rb

    config.root = Rails.root.join('tmp')
    config.cache_dir = 'carrierwave'
  
    config.fog_provider = 'fog/aws'
    config.fog_credentials = {
      provider: 'AWS',
      aws_access_key_id: ENV['S3_KEY'],
      aws_secret_access_key: ENV['S3_SECRET'],
      region: ENV['S3_REGION'],
    }
    config.fog_directory = ENV['S3_BUCKET_NAME']
    config.fog_public = false 
    config.fog_authenticated_url_expiration = 1.day.seconds.to_i
    config.fog_attributes = { 'Cache-Control'.freeze => "max-age=#{365.days.to_i}" } 
    config.storage = :fog

Attachment.rb (My model)

  mount_uploader :file, AttachmentUploader
  store_in_background :file

base_uploader.rb

class BaseUploader < CarrierWave::Uploader::Base
  def store_dir
    dir = model.id.to_s.delete('-').chars.each_slice(4).map(&:join).join('/')
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{dir}"
  end

carrierwave_backgrounder.rb

CarrierWave::Backgrounder.configure do |c|
  c.backend :sidekiq, queue: :carrierwave
end

I tried this configuration and It is working on my local. When I deploy to AWS ECS instance, I tried and I gave this error:
Errno::ENOENT: No such file or directory @ rb_sysopen - /my-app/tmp/carrierwave/1691423861-1-0001-1945/mrousavy7655566049517993747.jpg

I checked permission and location, permission is 755 and the file is in the location.

That line gives an error in my AWS ECS instance:

File.open(cache_path) { |f| record.send :"#{column}=", f }

It is likely that the cache directory does not exist on the server processing the job.
This is necessary for using store_in_background. Can you confirm that you have persistent storage accessible between instances?

hello again @lardawge,

Thanks for replying,

Yes, I check the path and I saw this path and this file: /my-app/tmp/carrierwave/1691423861-1-0001-1945/mrousavy7655566049517993747.jpg

I checked the folder and file permission too and it was 755.

Screenshot 2023-08-08 at 12 29 24

It gives that error:

Errno::ENOENT: No such file or directory @ rb_sysopen - /my-app/tmp/carrierwave/1691423861-1-0001-1945/mrousavy7655566049517993747.jpg

The project is in the AWS ECS instance. And when I call Rails.root it gives "/my-app".

I thought the file wasn't in the location but It is.

My suggestion would be to ssh into the server and see if you can run the job in the console to confirm that it still throws an error.

Can you post up some info about your stack? What version of rails, carrierwave, and fog.

I would also recommend taking a look at carrierwave-aws vs fog. It is lighter weight and faster.

Closing until I get more info.

I have a 1.0-beta branch up with more thorough testing using a rails app. Read the README for changes and look at the dummy_app in spec/support for setup.

If you are still having an issue, please add more details so I can replicate it.

Thank you,

I let you know!