Renaming uploaded files with Carrierwave

后端 未结 6 810
我寻月下人不归
我寻月下人不归 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:35

    From the Google Group:

    def filename
      @name ||= "#{secure_token}.#{file.extension}" if original_filename
    end
    
    private
    
    def secure_token
      ivar = "@#{mounted_as}_secure_token"
      token = model.instance_variable_get(ivar)
      token ||= model.instance_variable_set(ivar, ActiveSupport::SecureRandom.hex(4))  
    end
    

提交回复
热议问题