Hi, I have a multipart form upload field uploaded through <%file_field("profile", "profile") %> Once a submit happens, the action basically does something like: profile = Profile.new(params["picture"]) This invokes the models = to method: def picture=(picture_field) ...do a bunch of assignments here end def validate ... do a bunch of validations before saving end # do the actual file handling stuff here. def after_save end My question is, is the after_save method the right place to put the File manipulation stuff to copy and save the file on a directory on my local webserver filesystem? Also, how do I get access to the actual file in the after_save so that I could do stuff like the following: file.local_path (basically work with the file object so that I could copy it over from its local path onto my filesystem) and one more question, how do I pass stuff into this function that comes from the controller but is not necessarily an attribute of the Profile model? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060509/f7b80e85/attachment-0001.html
Dorian Mcfarland
2006-May-09 04:21 UTC
[Rails] handling file upload onto local filesystem.
you could try using the file_column plugin. makes things very easy to handle and you can do image processing (with rmagick installed): http://www.kanthak.net/opensource/file_column/ that''s my easy answer... dorian Sam Donaldson wrote:> Hi, > > I have a multipart form upload field uploaded through <%= > file_field("profile", "profile") %> > > Once a submit happens, the action basically does something like: > > profile = Profile.new (params["picture"]) > > This invokes the models = to method: > > def picture=(picture_field) > ...do a bunch of assignments here > end > > def validate > ... do a bunch of validations before saving > end > > # do the actual file handling stuff here. > def after_save > > end > > My question is, is the after_save method the right place to put the File > manipulation stuff to copy and save the file on a directory on my local > webserver filesystem? Also, how do I get access to the actual file in > the after_save so that I could do stuff like the following: > > file.local_path (basically work with the file object so that I could > copy it over from its local path onto my filesystem) > > and one more question, how do I pass stuff into this function that comes > from the controller but is not necessarily an attribute of the Profile > model? > > Thanks in advance. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- -- I do things for love or money
Hi, I decided against the file_column plugin due to some limitations in how i''d have to access a file in a view using url_for_file_column. Are there any other suggestions on my question, like on passing variables down to the model from the controller? Thanks. On 5/8/06, Dorian Mcfarland <loaf@isness.org> wrote:> > you could try using the file_column plugin. > makes things very easy to handle and you can do image processing (with > rmagick installed): > > http://www.kanthak.net/opensource/file_column/ > > that''s my easy answer... > > dorian > > > Sam Donaldson wrote: > > Hi, > > > > I have a multipart form upload field uploaded through <%> > file_field("profile", "profile") %> > > > > Once a submit happens, the action basically does something like: > > > > profile = Profile.new (params["picture"]) > > > > This invokes the models = to method: > > > > def picture=(picture_field) > > ...do a bunch of assignments here > > end > > > > def validate > > ... do a bunch of validations before saving > > end > > > > # do the actual file handling stuff here. > > def after_save > > > > end > > > > My question is, is the after_save method the right place to put the File > > manipulation stuff to copy and save the file on a directory on my local > > webserver filesystem? Also, how do I get access to the actual file in > > the after_save so that I could do stuff like the following: > > > > file.local_path (basically work with the file object so that I could > > copy it over from its local path onto my filesystem) > > > > and one more question, how do I pass stuff into this function that comes > > from the controller but is not necessarily an attribute of the Profile > > model? > > > > Thanks in advance. > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > -- > -- > I do things for love or money > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060509/59a00e34/attachment.html