在Rails中,我应该使用什么数据类型来存储大型文本文件和二进制数据

时间:2022-06-01 21:29:56

I need to store some binary files (spreadsheets) and some web pages in my table in SQLite DB in Rails. I know that storing files in the DB isn't a good practice but in this case, the convenience outweighs all else since I only need to store files rarely. Thank you.

我需要将一些二进制文件(电子表格)和一些web页面存储在Rails的SQLite DB中。我知道在DB中存储文件并不是一个很好的实践,但是在这种情况下,因为我只需要很少的存储文件,所以它的便利性比其他的都重要。谢谢你!

2 个解决方案

#1


3  

You should use the BLOB type for this purpose.

您应该为此目的使用BLOB类型。

#2


3  

The binary data type maps to to the BLOB in SQLite. The size can be specified by using the limit parameter. Here's an example from an self.up method of a migration:

二进制数据类型映射到SQLite中的BLOB。可以使用limit参数指定大小。这是一个自我的例子。向上迁移的方法:

t.column :mystuff, :binary, :limit => 10.megabyte

#1


3  

You should use the BLOB type for this purpose.

您应该为此目的使用BLOB类型。

#2


3  

The binary data type maps to to the BLOB in SQLite. The size can be specified by using the limit parameter. Here's an example from an self.up method of a migration:

二进制数据类型映射到SQLite中的BLOB。可以使用limit参数指定大小。这是一个自我的例子。向上迁移的方法:

t.column :mystuff, :binary, :limit => 10.megabyte