Hi all, I have set up a small system for uploading files following the excellent http://manuals.rubyonrails.com/read/chapter/78 At the bottom it addresses an issue with files uploaded through IE having the full path on the local machine instead of just the filename. The solution is File.basename() which I find does not work with Windows paths (and it says so in the documentation--http://www.ruby-doc.org/core/classes/File.html#M000025). The path must be separated through / which Windows paths are not. Any ideas on how to prevent this and get a clean name out of a IE upload? Many thanks in advance, Nicky
Nickolay Kolev wrote:> I have set up a small system for uploading files following the excellent > > http://manuals.rubyonrails.com/read/chapter/78Glad you find it useful.> At the bottom it addresses an issue with files uploaded through IE > having the full path on the local machine instead of just the filename. > The solution is File.basename() which I find does not work with Windows > paths (and it says so in the > documentation--http://www.ruby-doc.org/core/classes/File.html#M000025). > The path must be separated through / which Windows paths are not.Thanks for pointing this out. I had only tested on my windows machine where File.basename will happily deal with slashes that point the wrong way. WINXP: irb(main):024:0> File.basename(''C:\Documents and Files\user_name\Pictures\My File.jpg '') => "My File.jpg " vs. DEBIAN: irb(main):020:0> File.basename(''C:\Documents and Files\user_name\Pictures\My File.jpg'') => "C:\\Documents and Files\\user_name\\Pictures\\My File.jpg" A few tries and one gsub later, it looks like we''re back on track: irb(main):025:0> File.basename(''C:\Documents and Files\user_name\Pictures\My File.jpg''.gsub(''\\'',''/'')) => "My File.jpg" Please let me know if that works for you too, since mine is only a test in theory. -- Lee
> A few tries and one gsub later, it looks like we''re back on track: > > irb(main):025:0> File.basename(''C:\Documents and > Files\user_name\Pictures\My File.jpg''.gsub(''\\'',''/'')) > => "My File.jpg"Thanks a lot. I will test it on monday on a windows machine and tell you how it goes. Nicky
> A few tries and one gsub later, it looks like we''re back on track: > > irb(main):025:0> File.basename(''C:\Documents and > Files\user_name\Pictures\My File.jpg''.gsub(''\\'',''/'')) > => "My File.jpg" > > Please let me know if that works for you too, since mine is only a > test in theory.Thanks a lot. I will test it on monday on a windows machine and tell you how it goes. Nicky