本文整理汇总了Python中cherrypy.lib.static.serve_fileobj方法的典型用法代码示例。如果您正苦于以下问题:Python static.serve_fileobj方法的具体用法?Python static.serve_fileobj怎么用?Python static.serve_fileobj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cherrypy.lib.static
的用法示例。
在下文中一共展示了static.serve_fileobj方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_fileobj [as 别名]
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"