Using rest-client to download a file to disk without loading it all in memory first

后端 未结 2 1836
天命终不由人
天命终不由人 2021-02-08 12:25

I am using rest-client to download large page (around 1.5 GB in size). Retrieved value is stored in memory than saved into a file. As result my program crashes with failed

2条回答
  •  佛祖请我去吃肉
    2021-02-08 13:01

    Another way is to use raw_response. This saves directly to a file, usually in /tmp and handles redirects without a problem. See Streaming Responses. Here's their example:

    >> raw = RestClient::Request.execute(
               method: :get,
               url: 'http://releases.ubuntu.com/16.04.2/ubuntu-16.04.2-desktop-amd64.iso',
               raw_response: true)
    => , @request=>
    >> raw.file.size
    => 1554186240
    >> raw.file.path
    => "/tmp/rest-client.20170522-5346-1pptjm1"
    

提交回复
热议问题