title: appengine send data as a file download
body: <p>I'm new to python and appengine.So I have this simple problem.I want to send the server data and have the server send it back as a file download.I can get a file to download if I do it before a page loads. But after that I can't get the download.Here is what I have right now:</p>
  
  <pre><code>class UploadHandler(webapp.RequestHandler):
  
    def get(self):
      try:    
          xml=parseString(self.request.body)
          result=sanitize(xml)
          if result == None:
            text=xml.toxml('UTF-8')
            name="file.xml"   
            self.response.out.write(text)
            self.response.headers.add_header('Method','get')
            self.response.headers.add_header('Content-Type','text/xml')
            self.response.headers.add_header('name',name)
            self.response.headers.add_header('Content-Disposition','attachment')
            self.response.headers.add_header('filename',name)
            self.response.headers.add_header('Content',text)
     except:
          print self.request.body
  </code></pre>
  
  <p>And here is the javascript to call it:</p>
  
  <pre><code>        var text=getMarkup();
          new Ajax.Request("http://localhost:8080/file",{
          method:'get',
          contentType:"text",
          postBody:text,
          onSuccess:function(){
              console.log(transport.responseText);            
          },          
          onFailure: function(){ 
              console.log('Could not load file...'); 
          },
          onException: function(req,exception) {
              console.log(exception);
              return true;
              }, 
          });
  </code></pre>
  
  <p>I've tried changing both pieces many different ways.I can get a response, but I can't get it to go to the downloads.If I use the same code for the main page it works though.What am I missing?</p>
  
  <p>Finally got it....
  I use the example on this page <a href="https://developers.google.com/appengine/docs/python/blobstore/overview" rel="nofollow">here</a>
  only I sent the url back as the response and used window.open in the "onsuccess" handler to open it. </p>
  
  <p>The problem with the blobstore is that the files are saved on the server and other people can view them, so my best solution is just to use a global variable to save the data from the post and then pass it to get and call get from javascript with window.open().</p>