本文整理匯總了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"