Skip to content

How to: Upload files from a remote location to JSONB or Array image column

ErgoLau edited this page Dec 9, 2020 · 2 revisions

Let say we have an Avatar model with an image column of array data type.

To create a new Avatar record with an image

avatar = Avatar.new
avatar.remote_image_urls = ['https://image.flaticon.com/icons/png/512/25/25231.png']
avatar.save

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 free 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.

Clone this wiki locally