简体   繁体   中英

image name is not saved as original image name using CarrierWave in rails

I am using CarrierWave to upload images which will store into public -> uploads folder.

In my uploader.rb file, code structure is to give filename is like this,

def filename
"image.#{File.extname(original_filename).downcase}" if original_filename
end

But all images saved as images.jpg. But i want to save image with original name like if i will upload image which contain name like car.jpg than image would be saved as car.jpg not as image.jpg in public -> uploads folder.

If any one knows about this issue, please help me.

Thanks.

You could do something like:

def filename
    model.file_name
end

where file_name is the attribute on whatever you are uploading that contains the filename (if you want the extension, append it like you already do).

In your current code the file will be saved as 'image' (because you hardcoded "image.". You could also try

"#{original_filename}.#{File.extname(original_filename).downcase}" if original_filename

if original_filename is what you are expecting it to be).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM