Skip to content

Instantly share code, notes, and snippets.

@arikan
Created July 22, 2008 15:43
Show Gist options
  • Save arikan/1094 to your computer and use it in GitHub Desktop.
Save arikan/1094 to your computer and use it in GitHub Desktop.
Upload a file from a remote URL
def get_remote_file(uri)
require 'open-uri'
begin
uploadedfile = nil
open(uri) do |remote|
uploadedfile = StringIO.new(remote.read)
filename = File.basename(uri)
(class << uploadedfile; self; end).class_eval do
define_method(:local_path) { "" }
define_method(:original_filename) { filename }
define_method(:content_type) { "application/octet-stream" }
end
end
return uploadedfile
rescue
return ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment