Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions boto3/s3/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down Expand Up @@ -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::

Expand Down Expand Up @@ -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::

Expand Down
12 changes: 11 additions & 1 deletion docs/source/guide/s3-example-download-file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.