title: Why does using OpenURI to download a file result in a partial file?
body: <p>I'm trying to use OpenURI to download a file from S3, and then save it locally so I can send the file as an attachment with ActionMailer.</p>
  <p>Something strange is going on. The images being downloaded and attached are corrupt, the bottom parts of the images are missing.</p>
  <p>Here's the code:</p>
  <pre><code>require 'open-uri'
  open(&quot;#{Rails.root.to_s}/tmp/#{a.attachment_file_name}&quot;, &quot;wb&quot;) do |file|  
    source_url = a.authenticated_url()
    io = open(URI.parse(source_url).to_s)
    file &lt;&lt; io.read
    attachments[a.attachment_file_name] = File.read(&quot;#{Rails.root.to_s}/tmp/#{a.attachment_file_name}&quot;)        
  end
  </code></pre>
  <p><code>a</code> is the attachment from ActionMailer.</p>
  <p>What can I try next?</p>