title: Rails: How to send file from S3 to remote server
body: <p>I've been hunting around and can't seem to find a good solution for this. My Rails app stores it's files in Amazon S3. I now need to send them to a remote (3rd party) service.</p>
  
  <p>I'm using RestClient to post to the 3rd party server like this:</p>
  
  <pre><code>send_file = RestClient::Request.execute(
      :method =&gt; :post,
      :url =&gt; "http://remote-server-url.com",
      :payload =&gt; File.new("some_local_file.avi", 'rb'),
      :multipart =&gt; true,
      etc.... )
  </code></pre>
  
  <p>It works for local files, but how can I send a remote file from S3 directly to this 3rd party service?</p>
  
  <p>I found an answer here where someone was using open-uri: <a href="https://stackoverflow.com/questions/4422956/ruby-reading-files-from-s3-with-open-uri">ruby reading files from S3 with open-URI</a></p>
  
  <p>I tested that for myself, and it worked.</p>
  
  <pre><code>:payload =&gt; open(URI.parse("http://amazon-s3-example.com/some_file.avi"))
  </code></pre>
  
  <p>But, I've read a comment here that says open-uri simply loads the remote file into memory. See last comment on this answer: <a href="https://stackoverflow.com/a/264239/2785592">https://stackoverflow.com/a/264239/2785592</a></p>
  
  <p>This wouldn't be ideal, as I'm handling potentially large video files. I've also read somewhere the RestClient loads even local files into memory; again, this isn't ideal. Does anyone know if that's true?</p>
  
  <p>Surely I can't be the only one that has this problem. I know I could download the S3 file locally before sending it, but I was hoping to save on time &amp; bandwidth. Also, if RestClient truly <em>does</em> load even local files to memory, than downloading it locally doesn't save me anything. Heh heh.</p>
  
  <p>Any advice would be much appreciated. Thanks :)</p>
  
  <p><strong>Update:</strong>
  The remote server is just an API that responds to post requests. I don't have the ability to change anything on their end.</p>