Rails - Given a File Form Posted, How to Store in the DB and then Read later?
Given a Rails Form Post with X number of files.
- How do you store the file in the Database?
Then, later, how do you then read the file?
Than开发者_开发百科ks.
A little more background. The file form post is from SendGrid's parse api. Then later I want to be able to read the file with delayed_job and then use paperclip to store the file and process it on S3.
Thanks
Pretty sure I just answered your other question the same way: https://github.com/jstorimer/delayed_paperclip does what you seem to want it to do.
Based on the limited information I know about your system, I'm assuming you've got some model that tracks the emails. That's a good start.
First I would like to clarify that in no situation should you be storing files in the database. Files go in the filesystem, where they can be read and written much faster.
Now with that in mind, I would have a model that associates with your email model, possibly called Part
. This model's purpose will be to use Paperclip to store the files. I would call the attachment part
also, and so to create a new one you would do this:
email.parts.build(:part => some_file)
In that case, Paperclip will take care of moving the file to where it needs to be. To read the file later, Paperclip has methods for that. Check out Paperclip's documentation, it's pretty good for this sort of thing.
精彩评论