diff --git a/boto3/s3/inject.py b/boto3/s3/inject.py index 770a3aaa44..1f5beebf46 100644 --- a/boto3/s3/inject.py +++ b/boto3/s3/inject.py @@ -805,6 +805,9 @@ def download_fileobj( This is a managed transfer which will perform a multipart download in multiple threads if necessary. + If you plan to read from the file-like object after the download completes + and before closing it, call ``Fileobj.flush()`` and ``Fileobj.seek(0)`` + first. Usage:: @@ -871,6 +874,9 @@ def bucket_download_fileobj( This is a managed transfer which will perform a multipart download in multiple threads if necessary. + If you plan to read from the file-like object after the download completes + and before closing it, call ``Fileobj.flush()`` and ``Fileobj.seek(0)`` + first. Usage:: @@ -920,6 +926,9 @@ def object_download_fileobj( This is a managed transfer which will perform a multipart download in multiple threads if necessary. + If you plan to read from the file-like object after the download completes + and before closing it, call ``Fileobj.flush()`` and ``Fileobj.seek(0)`` + first. Usage:: diff --git a/docs/source/guide/s3-example-download-file.rst b/docs/source/guide/s3-example-download-file.rst index a4208585fa..44c796f6ec 100644 --- a/docs/source/guide/s3-example-download-file.rst +++ b/docs/source/guide/s3-example-download-file.rst @@ -36,6 +36,17 @@ object must be opened in binary mode, not text mode. with open('FILE_NAME', 'wb') as f: s3.download_fileobj('amzn-s3-demo-bucket', 'OBJECT_NAME', f) +If you need to read from the same file object before closing it, call +``flush()`` and then ``seek(0)`` first: + +.. code-block:: python + + with open('FILE_NAME', 'wb+') as f: + s3.download_fileobj('amzn-s3-demo-bucket', 'OBJECT_NAME', f) + f.flush() + f.seek(0) + data = f.read() + Like their upload cousins, the download methods are provided by the S3 ``Client``, ``Bucket``, and ``Object`` classes, and each class provides @@ -52,4 +63,3 @@ The download method's ``Callback`` parameter is used for the same purpose as the upload method's. The upload and download methods can both invoke the same ``Callback`` class. -