Carrierwave is a classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks.
I am going to demonstrate How to: Upload files from a remote location to JSONB or Array image column. For installation and configuration, I would recommend you to read Carrierwave document.
Let say we have an Avatar model with an image
column of array data type.
To create a new Avatar record with an image:
1 2 3 |
|
Note: We use remote_image_urls
for jsonb or array data type column while we use remote_image_url
for string data type column.
Please feel tree to replace image
to any column name you use to store the file or image. e.g If your Avatar model has a column named photo
, then you might want to modify the syntax above to remote_photo_url
and remote_photo_urls
.
You can dig deeper to its source code here.
Happy coding!