generate functionWed, 01 Mar 2023

rails download remote file to temp file

require 'tempfile' require 'open-uri' def download(url) file = Tempfile.new(['foobar','.jpg']) file.binmode file.write(open(url).read) file.close return file.path end download("https://koenig-media.raywenderlich.com/uploads/2016/08/Puppy.jpg")

Questions about programming?Chat with your personal AI assistant