Active Storage uploading files from a remote location

29 views
Skip to first unread message

Anton Ipatov

unread,
Mar 23, 2018, 7:35:29 AM3/23/18
to Ruby on Rails: Talk
How to add ability to upload image via URL?

Walter Lee Davis

unread,
Mar 23, 2018, 8:27:14 AM3/23/18
to rubyonra...@googlegroups.com
ActiveStorage accepts a file as a parameter, so all you need do is get an IO handle to the remote file, something like this:

require 'open-uri'
remote = open('url/to/file').read
@my_parent_object.file = remote
@my_parent_object.save

Walter

> On Mar 23, 2018, at 7:35 AM, Anton Ipatov <ipato...@gmail.com> wrote:
>
> How to add ability to upload image via URL?
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/26ae9fca-3082-4250-b20e-9b8d90d6ede6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages