本文整理汇总了Python中typing.BinaryIO.seekable方法的典型用法代码示例。如果您正苦于以下问题:Python BinaryIO.seekable方法的具体用法?Python BinaryIO.seekable怎么用?Python BinaryIO.seekable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typing.BinaryIO
的用法示例。
在下文中一共展示了BinaryIO.seekable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import seekable [as 别名]
def put(
self, namespace: str, metadata: Dict[str, Any], bytes_io: BinaryIO,
) -> None:
"""Store a file."""
subset = dict_subset(metadata, lambda k, v: k in (
# We are not storing the 'file_name'
'image_width', 'image_height', 'original_id', 'version'))
self._convert_values_to_str(subset)
if hasattr(bytes_io, 'seekable') and bytes_io.seekable():
bytes_io.seek(0)
# When botocore.response.StreamingBody is passed in as bytes_io,
# the bucket.put_object() call below fails with
# "AttributeError: 'StreamingBody' object has no attribute 'tell'"
# so we have to read the stream, getting the bytes:
if not hasattr(bytes_io, 'tell'):
bytes_io = bytes_io.read() # type: ignore
result = self.bucket.put_object(
Key=self._get_path(namespace, metadata),
# done automatically by botocore: ContentMD5=encoded_md5,
ContentType=metadata['mime_type'],
ContentLength=metadata['length'], Body=bytes_io, Metadata=subset)
# print(result)
return result