I've been looking for a while at the Cloudinary documentation but can't figure out how to upload multiple files to it using Rails and a html form.
I added Cloudinary support to my Carrierwave ImageUploader
include Cloudinary::CarrierWave
and I added my api-key and secret to config/cloudinary.yml
but what more do I need to change? For now, I kept everything as it was with carrierwave. So my form holds a file field
<%=file_field_tag "images[]", type: :file, multiple: true %>
and then for every image a new picture
instance gets created, and every picture instance holds a :image
attribute
if params[:images]
params[:images].each do |image|
@post.pictures.create(image: image)
end
end
I kept my ImageUploader
more or less default.
class ImageUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
When I upload some images, the urls are linking to a cloudinary page, but nothing has been actually uploaded to cloudinary. Can I just add something to the create
action of the picture
controller to actually upload the image? Something like
def create
@picture = Picture.new(picture_params)
@picture.save
Cloudinary::Uploader.upload(picture_params)
end