title: How to save an image from a url with rails active storage?
body: <p>I'm looking to save a file (in this case an image) located on another http web server using rails 5.2 active storage.</p>
  
  <p>I have an object with a string parameter for source url. Then on a before_save I want to grab the remote image and save it.</p>
  
  <p>Example: URL of an image <a href="http://www.example.com/image.jpg" rel="noreferrer">http://www.example.com/image.jpg</a>.</p>
  
  <pre><code>require 'open-uri'
  
  class User &lt; ApplicationRecord
    has_one_attached :avatar
    before_save :grab_image
  
    def grab_image
      #this indicates what I want to do but doesn't work
      downloaded_image = open("http://www.example.com/image.jpg")
      self.avatar.attach(downloaded_image)
    end
  
  end
  </code></pre>
  
  <p>Thanks in advance for any suggestions.</p>