Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 621

Show
Ignore:
Timestamp:
09/10/05 05:14:04
Author:
fumanchu
Message:

Added download method (serveFile demo) to tutorial 9.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/test/test_tutorials.py

    r577 r621  
    145145                         '</body></html>') 
    146146     
    147     def test09FileUpload(self): 
    148         self.load_tut_module("tut09_file_upload") 
     147    def test09Files(self): 
     148        self.load_tut_module("tut09_files") 
    149149         
     150        # Test upload 
    150151        h = [("Content-type", "multipart/form-data; boundary=x"), 
    151152             ("Content-Length", "110")] 
     
    165166        </body> 
    166167        </html>''') 
     168     
     169        # Test download 
     170        self.getPage('/download') 
     171        self.assertStatus("200 OK") 
     172        self.assertHeader("Content-Type", "application/x-download") 
     173        self.assertHeader("Content-Disposition", "attachment; filename=ReturnVsYield.pdf") 
     174        self.assertEqual(len(self.body), 326111) 
    167175 
    168176if __name__ == "__main__": 
  • trunk/cherrypy/tutorial/tut09_files.py

    r619 r621  
    11"""Tutorial: File upload""" 
    22 
     3import os 
     4localDir = os.path.dirname(__file__) 
     5absDir = os.path.join(os.getcwd(), localDir) 
     6 
    37import cherrypy 
     8from cherrypy.lib import cptools 
    49 
    510 
    6 class FileUploadDemo(object): 
     11class FileDemo(object): 
    712     
    813    def index(self): 
     
    3944        return out % (size, myFile.filename, myFile.type) 
    4045    upload.exposed = True 
     46     
     47    def download(self): 
     48        path = os.path.join(absDir, "ReturnVsYield.pdf") 
     49        return cptools.serveFile(path, "application/x-download", 
     50                                 "attachment", os.path.basename(path)) 
     51    download.exposed = True 
    4152 
    4253 
    43 cherrypy.root = FileUploadDemo() 
     54cherrypy.root = FileDemo() 
    4455 
    4556if __name__ == '__main__': 

Hosted by WebFaction

Log in as guest/cpguest to create tickets