title: send_file for a tempfile in Sinatra
body: <p>I'm trying to use Sinatra's built-in <a href="http://www.sinatrarb.com/intro.html#Sending%20Files" rel="nofollow"><code>send_file</code></a> command  but it doesn't seem to be working for tempfiles.</p>
  
  <p>I basically do the following to zip an album of mp3s:</p>
  
  <pre><code>get '/example' do
    songs = ...
    file_name = "zip_test.zip"
    t = Tempfile.new(['temp_zip', '.zip'])
    # t = File.new("testfile.zip", "w")
    Zip::ZipOutputStream.open(t.path) do |z|
      songs.each do |song|
        name = song.name
        name += ".mp3" unless name.end_with?(".mp3")
        z.put_next_entry(name)
        z.print(open(song.url) {|f| f.read })
        p song.name + ' added to file'
      end
    end
    p t.path
    p t.size
  
    send_file t.path, :type =&gt; 'application/zip',
                           :disposition =&gt; 'attachment',
                           :filename =&gt; file_name,
                            :stream =&gt; false
    t.close
    t.unlink
  end
  </code></pre>
  
  <p>When I use <code>t = File.new(...)</code> things work as expected, but I don't want to use <code>File</code> as it will have concurrency problems. </p>
  
  <p>When I use <code>t = Tempfile.new(...)</code>, I get:</p>
  
  <pre><code>!! Unexpected error while processing request: The file identified by body.to_path does not exist`
  </code></pre>
  
  <hr>
  
  <p>Edit: It looks like part of the problem is that I'm sending multiple files. If I just send one song, the Tempfile system works as well.</p>