-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud Storage upload_from_file does not work with files containing non-latin-1 characters. #818
Comments
Hi bc-lee, My understanding is that, as files are naturally stored in bytes on disk, opening a file in string mode is intended to be used for text processing only. In this case, we also have to upload in bytes, so opening a file in string mode only to then upload it to Storage would involve two conversions. The second conversion, that from a unicode string to bytes, is failing in this case because of a standard library method that says that RFC 2616 Section 3.7.1 dictates the default conversion in this case is latin-1. Can I ask more about your use case? Is there a particular reason why your application has file-like objects in string mode for this purpose? Thanks. |
Thanks for the reply. Can you add a comment or warning that in python-storage/google/cloud/storage/blob.py Line 2458 in 9e5329c
|
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 🦕
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
NOTE: Google Cloud Python client libraries are no longer maintained inside this repository. Please visit the python-API repository (e.g., https://github.com/googleapis/python-pubsub/issues) for faster response times.
See all published libraries in the README.
Sample code:
Then I get this error:
Traceback
Python and Google's python package versions are as follows:
Interestingly,
upload_from_string
works fine (i.e.b.upload_from_string(f.getvalue())
).This workaround is sufficient for me as my code uploads an in-memory file (
io.StringIO
), and the file is not large. However, I think it is necessary to modify the behavior of theupload_from_file
function somehow.The text was updated successfully, but these errors were encountered: