Renaming uploaded files with Carrierwave

后端 未结 6 802
我寻月下人不归
我寻月下人不归 2021-01-31 08:46

I\'m using Carrierwave to upload files, and I have it working.

My issue is attempting to change the name of the uploaded file.

In the generated uploader.rb there

6条回答
  •  走了就别回头了
    2021-01-31 09:48

    The other solution looks good, but how I did it then was to have a hook that created a random string for a new name on instance creation, then:

     def filename
        "#{model.randomstring}.#{model.image.file.extension}"
     end
    

    in the uploader.

    That worked, putting the random name generation as part of the model, then having carrierwave use that.

    I am curious which is faster, more effective, reasonable, sound, etc.

提交回复
热议问题