Class: ActiveStorage::Attached

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_com/active_storage/activestorage_attached.rb

Defined Under Namespace

Classes: One

Instance Method Summary collapse

Instance Method Details

#url_sync(url) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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