Files
openfoodnetwork/app/services/image_importer.rb
2023-06-16 21:23:44 +01:00

16 lines
348 B
Ruby

# frozen_string_literal: true
class ImageImporter
def import(url, product)
valid_url = URI.parse(url)
file = open(valid_url.to_s)
filename = File.basename(valid_url.path)
Spree::Image.create(
attachment: { io: file, filename: filename },
viewable_id: product.id,
viewable_type: Spree::Product,
)
end
end