Does Paperclip automatically clean up filenames?

前端 未结 2 1384
鱼传尺愫
鱼传尺愫 2021-02-19 14:12

I\'m using Thoughtbot\'s Paperclip gem to handle file uploads.

I\'m finding that when I upload a file with spaces in the filename, it gets stored with the spaces replace

相关标签:
2条回答
  • 2021-02-19 14:32

    OK, after a little more searching, I found this blog post that says, down at the bottom, that Paperclip actually does some minimal processing of filenames.

    0 讨论(0)
  • 2021-02-19 14:57

    To add a little more information, this happens in Paperclip::Attachment#cleanup_filename in which the default restricted_characters /[&$+,/:;=?@<>[]{}\|\\^~%# ]/ are replaced with underscores.

    It's not documented, but you can specify the :restricted_characters option to paperclip to change what gets replaced, e.g.

    class User < ActiveRecord::Base
      attr_accessible :avatar
      has_attached_file :avatar, :restricted_characters => /@/ # only replaces '@'
    end
    
    0 讨论(0)
提交回复
热议问题