Skip to content

Instantly share code, notes, and snippets.

@michalkorzawski
Last active October 30, 2022 22:04
Show Gist options
  • Select an option

  • Save michalkorzawski/bf487868d1cd48be02e1aa55e8dc9b3e to your computer and use it in GitHub Desktop.

Select an option

Save michalkorzawski/bf487868d1cd48be02e1aa55e8dc9b3e to your computer and use it in GitHub Desktop.
# records_controller.rb
@attaching_images = params[:record][:images].presence
if @attaching_images
@attaching_images = @attaching_images.map do |im|
io = ImageConverter.new(tempfile: im.tempfile, width: 1200).call
ActionDispatch::Http::UploadedFile.new(
{
filename: "#{im.original_filename.split('.').first}.jpg",
tempfile: io,
type: 'image/jpg',
head: "Content-Disposition: form-data; name=\"property[images][]\"; filename=\"#{im.original_filename.split('.').first}.jpg\"\r\nContent-Type: image/jpg\r\n"
}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment