ruby on rails - When using paperclip on Rails3, the some characters( @ and ~) get erased or altered from the file name when uploading -


I'm not sure that this is a paperclop problem. I tried it on gitlab and the same thing happened.

I have not written in the rail, there is a back end for the iOS app, and when I upload an image file with the @ character in the file name, it is erased by uploading, if I have a File, then

  aaa@2x.jpg   

it is saved

  aaa2x besides this, ~ _.  

This is a problem because iOS apps estimate that retina supported images are designated with a @ 2x prefix.

I can upload the name of the file and convert it to the database and rename the file, but it seems that there is a strange hack to do this, anyone know what Its going on? According to this file, how is the name of the file saved properly?

According to this article: You must be able to use any characters, including NULL in file names . But OS Epi can limit some characters for heritage reasons.

This may be a server or a client problem, try debugging your app and check the file name given in request.request_parameters valid file name.

If you are going to use the uploaded files in the URL then you should transliterate them before uploading, this will also solve your problem. ? You can use this extension to do this: | File

  module TransliteratePaperclip def transliterate_file_name (paperclip_file) paperclip_file = [paperclip_file] until paperclip_file.is_a (Enumerable) paperclip_file.each | Filename = read_attribute ("# {file} _file_name") if filename.present? Extension = File.extname (file name) .gsub (/^\.+/, '') file name = filename.gsub (/\.# {extension} $ /, '') self.send (file). Example_write (include: TransliteratePaperclip) putty: file_name, ". # {Filename.parameterize} # {extension.parameterize}") end-end end # extension ActiveRecord :: Base .send (include  /config/initializers/paperclip_transliterate.rb  in this code and in your paper clip model this code: | c  
  before_post_process {| transliterate_file_name (: file)}   

Where :. file is defined by attribute has_attached_file

Comments