GoodGets
2010-Mar-23 04:37 UTC
need to parse a User uploaded file, but don''t care if it''s saved
parsing the file''s not the problem, just not sure what to do with it before or after. I was thinking about uploading the files using Paperclip, parsing it, then deleting itfrom the database. But, that all seems a little unnecessary, especially if I don''t care if they are even saved. I then thought about grabbing them from the temp directory, but honestly wasn''t sure how to go about doing that. So before I really delve into the Tempfile, should I even worry about it in the first place? Each user uploaded file will be like 30kb max, and I''ll only be processing a couple hundred a month. Also, I''m hosted on heroku, so the s3 transfers (if I do save the file) will be free. What ya think? Any advice really is appreciated -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luke Pearce
2010-Mar-23 09:36 UTC
Re: need to parse a User uploaded file, but don''t care if it''s saved
Don''t know if this is any use - but you could just upload it yourself (rather than using paperclip or file_column): http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm You can choose the directory that you want it saved in, then delete the file as soon as you are done with it. Cheers Luke -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luke Pearce
2010-Mar-23 09:38 UTC
Re: need to parse a User uploaded file, but don''t care if it''s saved
Sorry just to add that tutorial saves it in a model - but obviously you don''t need to do that. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jeff Lewis
2010-Mar-23 15:35 UTC
Re: need to parse a User uploaded file, but don''t care if it''s saved
One way would be to just process the uploaded-file data from the request as needed and not worry about saving or doing anything else with the tmp-saved uploaded-file itself, something like: ### in ./app/models/uploadable_file.rb class UploadableFile ### for use in testing: def initialize(fname, contents) @fname = fname @contents = contents end def original_filename return @fname end def read return @contents end ### class meths: def self.parse(upfile) return nil if upfile.blank? or not (upfile.respond_to? (''original_filename'')\ and upfile.respond_to?(''read'')) orig_fname = upfile.original_filename contents = upfile.read # parse/process contents .... end end Then just call that class meth in your controller to parse the uploaded file for an example file form element of name "upfile": ### in some controller meth that handles that multipart/form-data form: ... parsed_contents = UploadableFile.parse(params[:upfile]) # check results .... Jeff On Mar 22, 9:37 pm, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> parsing the file''s not the problem, just not sure what to do with it > before or after. I was thinking about uploading the files using > Paperclip, parsing it, then deleting itfrom the database. But, that > all seems a little unnecessary, especially if I don''t care if they are > even saved. > > I then thought about grabbing them from the temp directory, but > honestly wasn''t sure how to go about doing that. So before I really > delve into the Tempfile, should I even worry about it in the first > place? Each user uploaded file will be like 30kb max, and I''ll only > be processing a couple hundred a month. Also, I''m hosted on heroku, > so the s3 transfers (if I do save the file) will be free. What ya > think? > > Any advice really is appreciated-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
GoodGets
2010-Mar-24 00:29 UTC
Re: need to parse a User uploaded file, but don''t care if it''s saved
@Luke: Thanks! Yeah, I saw that tutorial, too. But, also like you said, it still saves it to a model, so I''d rather just let paperclip handle all that. Thank you anyway though. @Jeff: Thank you! For full disclosure, I''m still a little bit of a noob to Rails (and ruby) but I think I get more than the gist of your code. So, definitely a big thanks. I do have a couple questions as to what''s going on though. Like I get that the file is read, along with its contents, but where is it read from? Like, is the file actually uploaded to a temp directory, and you''re saying that I just don''t have to expressly mess with that directory? Or, is it just held in memory in a Rails process somewhere? Might that be worse than just storing the file, then deleting it later? I''m just asking, I honestly don''t know. Also, while the file uploads, a Rails process is not tied up, correct? It''s actually being buffered by the server? A big thank you Jeff, and to anyone else that wants to chime in. I think this is definitely a huge start down the right path. On Mar 23, 11:35 am, Jeff Lewis <jeff.bu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> One way would be to just process the uploaded-file data from the > request as needed and not worry about saving or doing anything else > with the tmp-saved uploaded-file itself, something like: > > ### in ./app/models/uploadable_file.rb > class UploadableFile > > ### for use in testing: > > def initialize(fname, contents) > @fname = fname > @contents = contents > end > > def original_filename > return @fname > end > > def read > return @contents > end > > ### class meths: > > def self.parse(upfile) > return nil if upfile.blank? or not (upfile.respond_to? > (''original_filename'')\ > and upfile.respond_to?(''read'')) > > orig_fname = upfile.original_filename > contents = upfile.read > # parse/process contents .... > end > end > > Then just call that class meth in your controller to parse the > uploaded file for an example file form element of name "upfile": > > ### in some controller meth that handles that multipart/form-data > form: > ... > parsed_contents = UploadableFile.parse(params[:upfile]) > # check results .... > > Jeff > > On Mar 22, 9:37 pm, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > parsing the file''s not the problem, just not sure what to do with it > > before or after. I was thinking about uploading the files using > > Paperclip, parsing it, then deleting itfrom the database. But, that > > all seems a little unnecessary, especially if I don''t care if they are > > even saved. > > > I then thought about grabbing them from the temp directory, but > > honestly wasn''t sure how to go about doing that. So before I really > > delve into the Tempfile, should I even worry about it in the first > > place? Each user uploaded file will be like 30kb max, and I''ll only > > be processing a couple hundred a month. Also, I''m hosted on heroku, > > so the s3 transfers (if I do save the file) will be free. What ya > > think? > > > Any advice really is appreciated-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jeff Lewis
2010-Mar-24 17:26 UTC
Re: need to parse a User uploaded file, but don''t care if it''s saved
re: where is it read from?: I use passenger to serve my rails apps these days (all running on *nix), and per the passenger docs: http://www.modrails.com/documentation/Users%20guide.html#_passengertempdir_lt_directory_gt ... 5.10. PassengerTempDir <directory> Specifies the directory that Phusion Passenger should use for storing temporary files. This includes things such as Unix socket files, buffered file uploads, etc. ... The default for that on *nix is the /tmp dir. So, under such a setup, when a user uploads a file via the rails app, that uploaded file is temporarily saved under the /tmp dir. That''s why I was saying that if you didn''t want to save the file in terms of the app''s context, ie you just want to parse/process the uploaded file''s content, you shouldn''t have to do anything else with that /tmp file, since the underlying os will handle that clean up of /tmp files as necessary. Jeff On Mar 23, 5:29 pm, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @Luke: Thanks! Yeah, I saw that tutorial, too. But, also like you > said, it still saves it to a model, so I''d rather just let paperclip > handle all that. Thank you anyway though. > > @Jeff: Thank you! > For full disclosure, I''m still a little bit of a noob to Rails (and > ruby) but I think I get more than the gist of your code. So, > definitely a big thanks. > > I do have a couple questions as to what''s going on though. Like I get > that the file is read, along with its contents, but where is it read > from? Like, is the file actually uploaded to a temp directory, and > you''re saying that I just don''t have to expressly mess with that > directory? Or, is it just held in memory in a Rails process > somewhere? Might that be worse than just storing the file, then > deleting it later? > > I''m just asking, I honestly don''t know. Also, while the file uploads, > a Rails process is not tied up, correct? It''s actually being buffered > by the server? > > A big thank you Jeff, and to anyone else that wants to chime in. I > think this is definitely a huge start down the right path. > > On Mar 23, 11:35 am, Jeff Lewis <jeff.bu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > One way would be to just process the uploaded-file data from the > > request as needed and not worry about saving or doing anything else > > with the tmp-saved uploaded-file itself, something like: > > > ### in ./app/models/uploadable_file.rb > > class UploadableFile > > > ### for use in testing: > > > def initialize(fname, contents) > > @fname = fname > > @contents = contents > > end > > > def original_filename > > return @fname > > end > > > def read > > return @contents > > end > > > ### class meths: > > > def self.parse(upfile) > > return nil if upfile.blank? or not (upfile.respond_to? > > (''original_filename'')\ > > and upfile.respond_to?(''read'')) > > > orig_fname = upfile.original_filename > > contents = upfile.read > > # parse/process contents .... > > end > > end > > > Then just call that class meth in your controller to parse the > > uploaded file for an example file form element of name "upfile": > > > ### in some controller meth that handles that multipart/form-data > > form: > > ... > > parsed_contents = UploadableFile.parse(params[:upfile]) > > # check results .... > > > Jeff > > > On Mar 22, 9:37 pm, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > parsing the file''s not the problem, just not sure what to do with it > > > before or after. I was thinking about uploading the files using > > > Paperclip, parsing it, then deleting itfrom the database. But, that > > > all seems a little unnecessary, especially if I don''t care if they are > > > even saved. > > > > I then thought about grabbing them from the temp directory, but > > > honestly wasn''t sure how to go about doing that. So before I really > > > delve into the Tempfile, should I even worry about it in the first > > > place? Each user uploaded file will be like 30kb max, and I''ll only > > > be processing a couple hundred a month. Also, I''m hosted on heroku, > > > so the s3 transfers (if I do save the file) will be free. What ya > > > think? > > > > Any advice really is appreciated-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
GoodGets
2010-Mar-25 08:49 UTC
Re: need to parse a User uploaded file, but don''t care if it''s saved
So instead of saving the file somewhere, it''ll just grab it from the tmp directory, parse it, then leave it up to Rails or the server to expire the file after that request is over. Great, that''s exactly what I want. I plan on knocking this out tomorrow, and although I may have a question or two once I delve into it more, I at least understand what''s going on now. Big thanks Jeff, really do apreciate the help. On Mar 24, 1:26 pm, Jeff Lewis <jeff.bu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> re: where is it read from?: I use passenger to serve my rails apps > these days (all running on *nix), and per the passenger docs: > > http://www.modrails.com/documentation/Users%20guide.html#_passengerte... > > ... > 5.10. PassengerTempDir <directory> > Specifies the directory that Phusion Passenger should use for storing > temporary files. This includes things such as Unix socket files, > buffered file uploads, etc. > ... > > The default for that on *nix is the /tmp dir. So, under such a setup, > when a user uploads a file via the rails app, that uploaded file is > temporarily saved under the /tmp dir. That''s why I was saying that if > you didn''t want to save the file in terms of the app''s context, ie you > just want to parse/process the uploaded file''s content, you shouldn''t > have to do anything else with that /tmp file, since the underlying os > will handle that clean up of /tmp files as necessary. > > Jeff > > On Mar 23, 5:29 pm, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > @Luke: Thanks! Yeah, I saw that tutorial, too. But, also like you > > said, it still saves it to a model, so I''d rather just let paperclip > > handle all that. Thank you anyway though. > > > @Jeff: Thank you! > > For full disclosure, I''m still a little bit of a noob to Rails (and > > ruby) but I think I get more than the gist of your code. So, > > definitely a big thanks. > > > I do have a couple questions as to what''s going on though. Like I get > > that the file is read, along with its contents, but where is it read > > from? Like, is the file actually uploaded to a temp directory, and > > you''re saying that I just don''t have to expressly mess with that > > directory? Or, is it just held in memory in a Rails process > > somewhere? Might that be worse than just storing the file, then > > deleting it later? > > > I''m just asking, I honestly don''t know. Also, while the file uploads, > > a Rails process is not tied up, correct? It''s actually being buffered > > by the server? > > > A big thank you Jeff, and to anyone else that wants to chime in. I > > think this is definitely a huge start down the right path. > > > On Mar 23, 11:35 am, Jeff Lewis <jeff.bu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > One way would be to just process the uploaded-file data from the > > > request as needed and not worry about saving or doing anything else > > > with the tmp-saved uploaded-file itself, something like: > > > > ### in ./app/models/uploadable_file.rb > > > class UploadableFile > > > > ### for use in testing: > > > > def initialize(fname, contents) > > > @fname = fname > > > @contents = contents > > > end > > > > def original_filename > > > return @fname > > > end > > > > def read > > > return @contents > > > end > > > > ### class meths: > > > > def self.parse(upfile) > > > return nil if upfile.blank? or not (upfile.respond_to? > > > (''original_filename'')\ > > > and upfile.respond_to?(''read'')) > > > > orig_fname = upfile.original_filename > > > contents = upfile.read > > > # parse/process contents .... > > > end > > > end > > > > Then just call that class meth in your controller to parse the > > > uploaded file for an example file form element of name "upfile": > > > > ### in some controller meth that handles that multipart/form-data > > > form: > > > ... > > > parsed_contents = UploadableFile.parse(params[:upfile]) > > > # check results .... > > > > Jeff > > > > On Mar 22, 9:37 pm, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > parsing the file''s not the problem, just not sure what to do with it > > > > before or after. I was thinking about uploading the files using > > > > Paperclip, parsing it, then deleting itfrom the database. But, that > > > > all seems a little unnecessary, especially if I don''t care if they are > > > > even saved. > > > > > I then thought about grabbing them from the temp directory, but > > > > honestly wasn''t sure how to go about doing that. So before I really > > > > delve into the Tempfile, should I even worry about it in the first > > > > place? Each user uploaded file will be like 30kb max, and I''ll only > > > > be processing a couple hundred a month. Also, I''m hosted on heroku, > > > > so the s3 transfers (if I do save the file) will be free. What ya > > > > think? > > > > > Any advice really is appreciated-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.