How can I set the public ID as the original filename in Carrierwave?

If you upload the images from the server-side, then in order to use the original file name of the uploaded image for the public ID, you can add the following method to your upload:

def public_id
Cloudinary::PreloadedFile.split_format(original_filename).first + "_" + Cloudinary::Utils.random_public_id[0,6]
end

When uploading from the client-side, you can use something like the following:

<%= form_for(@photo) do |f| %>
...
<%= f.cl_image_upload(:image, use_filename: true) %>
end
Have more questions? Submit a request

Comments

Powered by Zendesk