'Rails 7 - superslow Carrierwave S3 AWA fog upload ONLY in localhost

I have switched to Rails 7 and I found some issues when I upload image in my localhost. The system idles for 10/30 sec even for 5kb images, picture will be correctly loaded.

Furthermore the server is also very slow when deleting images.

I underline that this happens only in localhost, not production.

Here is my code: carrierwave.rb

CarrierWave.configure do |config|

config.fog_provider = "fog/aws"
config.fog_credentials = {
    :provider               => 'AWS',                        # required
    :aws_access_key_id      => ENV['S3_ACCESS_KEY'],                        
    :aws_secret_access_key  => ENV['S3_SECRET_ACCESS_KEY'],    
    :region                 => ENV['S3_REGION']                          # optional, defaults to 'us-east-1' defaults to 'us-east-1'
}
config.fog_directory  = ENV['S3_BUCKET']                          # required
# config.fog_public     = true                                   # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
config.storage = :fog

image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
  process resize_to_fit: [300, 300]
end
version :default do 
  process resize_to_fit: [800,800]
end
version :big do 
  process resize_to_limit: [1200, nil]
end
end
end

the issue is shown during uploads in my active admin page, with standard form uploader, in console and also in seeds.rb file.

The gems I'm using for upload are:

  • carrierwave (2.2.2)
  • fog-aws (3.13.0)

What I have tried:

  • removing versions generation (nothing changed)
  • using RMagick instead of MiniMagick (nothing changed)
  • using storage :file (the upload was really fast) It seems the issue is related to fog.

The bucket is on S3 and it is working very well with a rails 5 application. My system is a last generation M1 MacBook pro.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source