Memory issues with HTTParty and download large files

前端 未结 1 1616
太阳男子
太阳男子 2021-02-10 11:53

Is this going to cause memory issues with Ruby. I know Open-URI writes to a TempFile if the size goes over 10KB. But will HTTParty try and save the whole PDF to memory before it

相关标签:
1条回答
  • 2021-02-10 12:22

    You can use Net::HTTP. See the documentation (in particular the section titled "Streaming Response Bodies").

    Here's the example from the docs:

    uri = URI('http://example.com/large_file')
    
    Net::HTTP.start(uri.host, uri.port) do |http|
      request = Net::HTTP::Get.new uri.request_uri
    
      http.request request do |response|
        open 'large_file', 'w' do |io|
          response.read_body do |chunk|
            io.write chunk
          end
        end
      end
    end
    
    0 讨论(0)
提交回复
热议问题