# How to create test data using migration for file\_column

**URL:** <https://www.ruby-forum.com/t/how-to-create-test-data-using-migration-for-file-column/150771>\
**Category:** Rails\
**Created:** [October 13, 2008, 5:19am UTC](https://www.ruby-forum.com/t/how-to-create-test-data-using-migration-for-file-column/150771 "2008-10-13T05:19:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casensio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@casensio](https://www.ruby-forum.com/u/casensio)\
**Post date:** [October 13, 2008, 5:19am UTC](https://www.ruby-forum.com/t/how-to-create-test-data-using-migration-for-file-column/150771/1 "2008-10-13T05:19:56Z")

</div>

Hi,

i would like to create test data for my client using migration.

for example:  
Model.create(  
:name =\> ‘john’,  
:age =\> ‘28’  
)

how would one do that for the file\_column “image” field? i have tried to  
give the name of the file XXXX.jpg, but i get the following error  
message:

“Do not know how to handle a string with value ‘XXXXX.jpg’ that was  
passed to a file\_column. Check if the form’s encoding has been set to  
‘multipart/form-data’.”

thanks a lot

---

<div class="post-metadata">

**Author:** ![casensio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@casensio](https://www.ruby-forum.com/u/casensio)\
**Post date:** [October 13, 2008, 3:05pm UTC](https://www.ruby-forum.com/t/how-to-create-test-data-using-migration-for-file-column/150771/2 "2008-10-13T15:05:06Z")

</div>

The easy way to display this is to just store the binary data of the  
file.

So you’d have a blob column called image…

Model.create(  
:name =\> ‘john’,  
:image =\> File.read(“/Path/To/Image/File/john.jpg”)  
)

Check out

> **[Uploading files to a database using Rails](https://matt.berther.io/2007/10/19/uploading-files-to-a-database-using-rails/)**
>
> Not long ago, I needed a way for users to upload files and store them in a database. The platform for the application was Ruby on Rails, and I wanted to share my experience here.

for some image handling tips.

On Oct 12, 11:19 pm, Cedric C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
