Skip to content

Commit

Permalink
docs: open file-like objects in byte mode for uploads (#824)
Browse files Browse the repository at this point in the history
File-like objects should be opened in binary mode for `blob.upload_from_file()`
- cpython standard library accorded with [RFC 2616 Section 3.7.1](https://datatracker.ietf.org/doc/html/rfc2616#section-3.7.1) states the text default charset of iso-8859-1
- add clarifying notes in docstring
- update code sample

Fixes #818 🦕
  • Loading branch information
cojenco committed Jul 22, 2022
1 parent 5e06dc0 commit 4bd3d1d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion google/cloud/storage/blob.py
Expand Up @@ -2456,7 +2456,7 @@ def upload_from_file(
to that project.
:type file_obj: file
:param file_obj: A file handle open for reading.
:param file_obj: A file handle opened in binary mode for reading.
:type rewind: bool
:param rewind:
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/storage_upload_from_stream.py
Expand Up @@ -25,8 +25,8 @@ def upload_blob_from_stream(bucket_name, file_obj, destination_blob_name):

# The stream or file (file-like object) from which to read
# import io
# file_obj = io.StringIO()
# file_obj.write("This is test data.")
# file_obj = io.BytesIO()
# file_obj.write(b"This is test data.")

# The desired name of the uploaded GCS object (blob)
# destination_blob_name = "storage-object-name"
Expand Down

0 comments on commit 4bd3d1d

Please sign in to comment.