Mattias Bodlund
2005-Nov-30 17:11 UTC
Get content_type of uploaded file when using file-column
I use the file-column plugin to handle a file upload module for a rails app. Plain and simple: class Media < ActiveRecord::Base file_column :file What I now would like is to get the contetn_type or the IOString object of the original uploaded file. file_column converts this to a string object containing the path to the file. Any idears? -- Posted via http://www.ruby-forum.com/.
Kyle Maxwell
2005-Nov-30 19:34 UTC
Re: Get content_type of uploaded file when using file-column
You can''t determine that from the extension of the uploaded file? What exactly are you trying to do? You can try to override the file= method alias_method :old_file=, :filedef file=(original_io) #do something with original io old_file=(original_io) end On 11/30/05, Mattias Bodlund <mattias-85ePeH3V+ZFknbxzx/v8hQ@public.gmane.org> wrote:> I use the file-column plugin to handle a file upload module for a rails > app. Plain and simple: > > class Media < ActiveRecord::Base > file_column :file > > What I now would like is to get the contetn_type or the IOString object > of the original uploaded file. file_column converts this to a string > object containing the path to the file. > > Any idears? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Mattias Bodlund
2005-Nov-30 21:32 UTC
Re: Get content_type of uploaded file when using file-column
kyle wrote:> You can''t determine that from the extension of the uploaded file? > What exactly are you trying to do? > > You can try to override the file= method > > alias_method :old_file=, :file> def file=(original_io) > #do something with original io > old_file=(original_io) > endI can''t make this work. File-column trabnsform the IO object to a String object (the files location) This happens before I can get my hands on the IOString object. I could moove this to the controller but that feels like the wrong place for this. -- Posted via http://www.ruby-forum.com/.
Jérôme L
2005-Dec-06 09:07 UTC
Re: Re: Get content_type of uploaded file when using file-column
On 11/30/05, Mattias Bodlund <mattias@oncotype.dk> wrote:> > kyle wrote: > > You can't determine that from the extension of the uploaded file? > > What exactly are you trying to do? > > > > You can try to override the file= method > > > > alias_method :old_file=, :file> > def file=(original_io) > > #do something with original io > > old_file=(original_io) > > end > > I can't make this work. File-column trabnsform the IO object to a String > object (the files location) This happens before I can get my hands on > the IOString object. > > I could moove this to the controller but that feels like the wrong place > for this.I feel the same but now I couldn't get the mime type from the model declaration (ideally in a before_create hook). Then I wrote in some controller: def save media = Media.new(params[:media]) # ... media.content_type = params[:media][:file].content_type.strip media.save end _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails