class ActiveStorage::Attached

Public Instance Methods

url_sync(url) click to toggle source
# File lib/rails_com/active_storage/activestorage_attached.rb, line 5
def url_sync(url)
  filename = File.basename URI(url).path

  Tempfile.open do |file|
    file.binmode
    HTTParty.get(url, stream_body: true) do |fragment|
      file.write fragment
    end

    file.rewind
    self.attach io: file, filename: filename
  end

end