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...@gmail.com> 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...@gmail.com> 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...@gmail.com> 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@googlegroups.com.
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.
No comments:
Post a Comment