本文整理汇总了Python中django.core.files.uploadedfile.TemporaryUploadedFile.flush方法的典型用法代码示例。如果您正苦于以下问题:Python TemporaryUploadedFile.flush方法的具体用法?Python TemporaryUploadedFile.flush怎么用?Python TemporaryUploadedFile.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.uploadedfile.TemporaryUploadedFile
的用法示例。
在下文中一共展示了TemporaryUploadedFile.flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_tempfile
# 需要导入模块: from django.core.files.uploadedfile import TemporaryUploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.TemporaryUploadedFile import flush [as 别名]
def _make_tempfile(self, filename, content):
fileobj = TemporaryUploadedFile(
name=filename + ".tempfile",
content_type='text/plain',
size=0,
charset='utf8',
)
fileobj.write(content)
fileobj.flush()
return fileobj
示例2: ensure_saved
# 需要导入模块: from django.core.files.uploadedfile import TemporaryUploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.TemporaryUploadedFile import flush [as 别名]
def ensure_saved(self, file):
"""This may create a temporary file, which will be deleted when
it's closed, so always close() it but only when you've finished!"""
if isinstance(file, InMemoryUploadedFile):
print "Writing %s to disk (%d bytes)" % (file, file.size)
tmp = TemporaryUploadedFile(name=file.name,
content_type=file.content_type, size=file.size,
charset=file.charset)
file.seek(0)
buf = file.read()
tmp.write(buf)
print "Wrote %d bytes" % len(buf)
tmp.flush()
else:
tmp = file
if isinstance(tmp, TemporaryUploadedFile):
path = tmp.temporary_file_path()
else:
path = tmp.name
return (tmp, path)