Downloading a Remote File

What is the best way to download a remote file? I have images on a legacy server that I need to download and store locally on my new server.

I see the remote_url plugin but that loads the remote files into a Tempfile.

If you need to do it as part of a migration, you can use the down gem directly:

Down.download("https://example.com/path/to/image.jpg", destination: "/path/to/destination.jpg")

I need to save the remote files to a new model in ActiveRecord though.

class User < ApplicationRecord
  include MyUploader[:avatar]
end

@user.avatar_remote_url = 'http://example.com/avatar.jpg'

This will only save a cached temporary file, right?

I want it to persist on disk like a normal file upload would.

The assigned remote file will be persisted in whatever Shrine storage you’ve defined. If you’re using FileSystem storage, both :cache and :store storage will store the file on a defined directory on disk, they won’t just be in a Tempfile.