I upload an image remotely using remote_url from CarrierWave on my Rails application. It used to work fine but now I get an issue
Controller
@pool = Pool.new(remote_main_picture_url: "https://myimageurl...")
if @pool.save //is causing the error
....
end
Uploader
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
def store_dir
"#{ENV['AWS_S3_BUCKET_NAME']}/#{model.class.to_s.underscore}/#{model.id}"
end
def extension_allowlist
%w(jpg jpeg gif png svg webp)
end
process resize_to_fit: [2000, 2000]
version :medium do
process resize_to_fit: [400, 400]
end
def filename
@name ||= "#{mounted_as}_#{timestamp}.png" if original_filename.present?
end
def timestamp
var = :"@#{mounted_as}_timestamp"
model.instance_variable_get(var) or model.instance_variable_set(var, Time.now.to_i)
end
end
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.0.2'
gem 'rails', '~> 6.1.4'
gem 'pg'
gem 'puma'
gem 'bootsnap', '1.10.3', require: false
gem "webpacker"
gem 'carrierwave', '~> 2.0'
gem 'fog-aws'
gem 'mini_magick'
Error message
NoMethodError (undefined method `closed?' for nil:NilClass
raise IOError, 'attempt to read body out of block' if @socket.closed?
The error seems to be linked to net/http, I don't know what has changed to cause this issue... Maybe a gemfile update...
Carrierwave install gem ssrf_filter like dependency and lasted version of this gem prodused this problem. You need install ssrf_filter gem of version '1.0.8'
gem 'ssrf_filter', '1.0.8'
More details on https://github.com/carrierwaveuploader/carrierwave/issues/2625