我正在使用Box
Python API编写一些工具.因此,其中一个是将文件上传到Box.他们使用StringIO作为目标文件.
我需要在本地读取文件并将其内容写入StringIO缓冲区,然后将其传递给Box API,如下面的代码所示:
def upload_file(self, filename, folder_id='0'):
assert self.client is not None
try:
stream = StringIO.StringIO()
# replace this line a file read
stream.write('Box Python SDK Test!')
stream.seek(0)
box_file = self.client.folder(folder_id=folder_id).upload_stream(
stream, filename,
preflight_check=True)
return box_file.name
except BoxAPIException, e:
self.log.exception(e)
很简单,我如何从本地文件中读取,然后写入StringIO缓冲区?