How to upload images to folders with CarrierWave

Follow

Comments

6 comments

  • Avatar
    Maicon Sanson Penna

    Do I must define a public_id with server-side? I only wanna create a folder and mantain the default public_id.

    Is it possible?

  • Avatar
    Nadav Ofir

    Hi, you can use our random_public_id method to generate a random public ID for the upload request, e.g.:

      def public_id
        return "my_folder/" + Cloudinary::Utils.random_public_id;
      end  
    
  • Avatar
    Pedro Henrique Knoll

    How can I use the

    <%= f.cl_image_upload(:image, :folder => "my_folder") %>

    with simple_form?

  • Avatar
    Maor Gariv

    Hi,
    Sorry for the very late reply, we have noticed that this request was left unattended. I guess this is not relevant anymore but if you have any further questions, feel free to reach out by opening a new support ticket -
    https://support.cloudinary.com/hc/en-us/requests/new

  • Avatar
    Ashrith

    Hi Maor Gariv/Itay Taragano,

        As updated recently by Itay Taragano, using public_id in the uploader class doesn't update the URL structure.

    And URL generated still looks like this: "https://res-3.cloudinary.com/cloud_name/image/upload/pic_08.png"

    And my public_id method looks as follows:

    def public_id
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end

    It still uses the `resource_type` and `type` instead of my model details as mentioned above. And i followed all the steps mentioned.

  • Avatar
    Daniel Mendoza

    Hi,

    To save the `public_id` with that structure to your uploader, you can do the following:

    def public_id
       "#{store_dir}/#{model.id}"
    end

    def filename
       "#{public_id}.#{file.extension}" if original_filename.present?
    end

    def store_dir
       "uploads/#{model.class.to_s.underscore}/#{mounted_as}"
    end

    Let me know if this works for you.

Please sign in to leave a comment.