简体   繁体   中英

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?

Thanks.

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

可以肯定的是,我以相同的方式回答了您的其他问题: https : //github.com/jstorimer/delayed_pa​​perclip完成了您似乎希望它执行的操作。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM