Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Save File using Ruby 2.2.3 and rest-client

I am trying to use a rest API to download a file, it appears to work, but I dont actually have a file downloaded. I am assuming its because its going to memory, and not to my file system.

Below is the portion of code responsible. My URL is slightly edited when pasting it below, and my authToken is valid.

backup_url = "#{proto}://#{my_host}/applications/ws/migration/export?noaudit=#{include_audit}&includebackup=#{include_backup_zips}&authToken=#{my_token}"
resource = RestClient::Resource.new(
  backup_url,
  :timeout => nil,
  :open_timeout => nil)
response = resource.get
if response.code == 200
    puts "Backup Complete"
else
    puts "Backup Failed"
    abort("Response Code was not 200: Response Code #{response.code}")
end

Returns:

# => 200 OK | application/zip 222094570 bytes
Backup Complete

There is no file present though.

Thanks,

like image 479
Justin S Avatar asked Dec 07 '15 18:12

Justin S


1 Answers

Well you actually have to write to the file yourself.

Pathname('backup.zip').write response.to_s
like image 118
Matthias Winkelmann Avatar answered Sep 19 '22 00:09

Matthias Winkelmann