Python cherrypy.lib.static.serve_file() Examples

The following are 13 code examples of cherrypy.lib.static.serve_file(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cherrypy.lib.static , or try the search function .
Example #1
Source File: tut09_files.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def download(self):
        path = os.path.join(absDir, 'pdf_file.pdf')
        return static.serve_file(path, 'application/x-download',
                                 'attachment', os.path.basename(path)) 
Example #2
Source File: server.py    From spyre with MIT License 6 votes vote down vote up
def download(self, **args):
        args = self.clean_args(args)
        filepath = self.getDownload(args)

        if type(filepath).__name__ == "str":
            return serve_file(filepath, "application/x-download", "attachment", name='data.csv')
        if type(filepath).__name__ == "instance":
            file_obj = serve_fileobj(
                filepath.getvalue(),
                "application/x-download",
                "attachment",
                name='data.csv'
            )
            return file_obj
        if type(filepath).__name__ == "StringIO":
            file_obj = serve_fileobj(
                filepath.getvalue().encode('utf-8'),
                "application/x-download",
                "attachment",
                name='data.csv'
            )
            return file_obj
        else:
            return "error downloading file. filepath must be string of buffer" 
Example #3
Source File: test_static.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def error_page_404(status, message, traceback, version):
    path = os.path.join(curdir, 'static', '404.html')
    return static.serve_file(path, content_type='text/html') 
Example #4
Source File: alarmdata.py    From SecPi with GNU General Public License v3.0 5 votes vote down vote up
def show_img(self, name, mimetype):
		fp = path.join(self.datapath, name)
		if(path.exists(fp)):
			return serve_file(fp, mimetype, name)
		else:
			tmpl = self.lookup.get_template("404.mako")
			cherrypy.response.status = 404
			return tmpl.render(page_title="File not found!") 
Example #5
Source File: alarmdata.py    From SecPi with GNU General Public License v3.0 5 votes vote down vote up
def download(self, name):
		fp = path.join(self.datapath, name)
		if(path.exists(fp)):
			return serve_file(fp, "application/x-download", "attachment")
		else:
			tmpl = self.lookup.get_template("404.mako")
			cherrypy.response.status = 404
			return tmpl.render(page_title="File not found!") 
Example #6
Source File: sample_custom_post.py    From telegram-rss-generation with MIT License 5 votes vote down vote up
def rss(self):
        # Return static file with ATOM feed
        return serve_file("/bots/telegram-feedgen-bot/static/atom.xml") 
Example #7
Source File: web_server.py    From OpenTracker with GNU General Public License v3.0 5 votes vote down vote up
def GET(self, id=None):
        """Write our image to a temp file, then give it back to the user"""
        cv2.imwrite(self.image_file, self.image_callback())
        return serve_file(self.image_file, content_type='image/jpeg') 
Example #8
Source File: tut09_files.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def download(self):
        path = os.path.join(absDir, 'pdf_file.pdf')
        return static.serve_file(path, 'application/x-download',
                                 'attachment', os.path.basename(path)) 
Example #9
Source File: test_static.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def error_page_404(status, message, traceback, version):
    path = os.path.join(curdir, 'static', '404.html')
    return static.serve_file(path, content_type='text/html') 
Example #10
Source File: tut09_files.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def download(self):
        path = os.path.join(absDir, 'pdf_file.pdf')
        return static.serve_file(path, 'application/x-download',
                                 'attachment', os.path.basename(path)) 
Example #11
Source File: test_static.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def error_page_404(status, message, traceback, version):
    path = os.path.join(curdir, 'static', '404.html')
    return static.serve_file(path, content_type='text/html') 
Example #12
Source File: tut09_files.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
def download(self):
        path = os.path.join(absDir, "pdf_file.pdf")
        return static.serve_file(path, "application/x-download",
                                 "attachment", os.path.basename(path)) 
Example #13
Source File: web_server.py    From ardupilot-balloon-finder with GNU General Public License v3.0 5 votes vote down vote up
def GET(self, id=None):
        """Write our image to a temp file, then give it back to the user"""
        cv2.imwrite(self.image_file, self.image_callback())
        return serve_file(self.image_file, content_type='image/jpeg')