Would it be possible to add a local file--i.e. a file that''s already on the file system--to the db using file_column? This would be nice to add a whole bunch of files in one run, like from an unzipped zip file. -- Regards, Charles.
I''m not expert, but I''d imagine you''d have to write some sort of ruby script to emulate the behavior of the file_column, but on multiple files. I can see how this would be useful for sites with existing images that want to switch over to using file_column. I think it''d be a nice feature to add. On 10/29/05, Charles Gerungan <charles.gerungan-ySWhhvebaBCQ1v0sGEeVBA@public.gmane.org> wrote:> Would it be possible to add a local file--i.e. a file that''s already > on the file system--to the db using file_column? This would be nice > to add a whole bunch of files in one run, like from an unzipped zip > file. > > -- > Regards, Charles. > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Ramin http://www.getintothis.com/blog
Charles, On 10/30/05, Charles Gerungan <charles.gerungan-ySWhhvebaBCQ1v0sGEeVBA@public.gmane.org> wrote:> Would it be possible to add a local file--i.e. a file that''s already > on the file system--to the db using file_column? This would be nice > to add a whole bunch of files in one run, like from an unzipped zip > file.right now you can''t assign a File object to a file_column managed attribute directly, because file_column expects the object to have a "original_filename" column. However, you could use Ruby''s singleton classes to just add this method to the file object you want to add. Something like this (completely untested) might work: file = File.new("/some/file") def file.original_filename filename end entry.image = file However, if you want to add several files from a zip archive, every file has to go into a different model object. Right now, file_column only supports one file per model and I probably won''t change this in order to keep things simple. Hope this helps Sebastian
Attached is the code that I use. Just require it from your environment. On 10/30/05, Sebastian Kanthak <skanthak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Charles, > > On 10/30/05, Charles Gerungan <charles.gerungan-ySWhhvebaBCQ1v0sGEeVBA@public.gmane.org> wrote: > > Would it be possible to add a local file--i.e. a file that''s already > > on the file system--to the db using file_column? This would be nice > > to add a whole bunch of files in one run, like from an unzipped zip > > file. > > right now you can''t assign a File object to a file_column managed > attribute directly, because file_column expects the object to have a > "original_filename" column. However, you could use Ruby''s singleton > classes to just add this method to the file object you want to add. > Something like this (completely untested) might work: > > file = File.new("/some/file") > def file.original_filename > filename > end > entry.image = file > > However, if you want to add several files from a zip archive, every > file has to go into a different model object. Right now, file_column > only supports one file per model and I probably won''t change this in > order to keep things simple. > > Hope this helps > Sebastian > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails