Posted over 7 years ago. Visible to the public.

Ruby: Downloading files

This is easy:

Copy
require 'open-uri' File.open('/target/path/to/downloaded.file', "wb") do |file| file.write open('http://example.com/your.file').read end

Basic Authentication

When your file is protected by HTTP Basic Authentication, pass your credentials as hash:

Copy
File.open('/target/path/to/downloaded.file', "wb") do |file| file.write open('http://example.com/your.file', :http_basic_authentication => [your_username, your_password]).read end

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
almost 3 years ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more