Is there an easy (or generally accepted) way to load up a binary column using the create method of ActiveRecord?
For example, what I'm trying to do is something similar to this:
MyTableObject.create(name: 'Test', image: File.read('PathToMyFile.jpg'))
I was able to get this working. Rather than doing:
MyTableObject.create(
name: 'Test',
image: File.read('PathToMyFile.jpg')
)
which did insert a record into the database but without the correct binary representation of the file
MyTableObject.create(
name: 'Test',
image: File.open('PathToMyFile.jpg', 'rb').read
)
seemed to do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With