How can I upload a file to Google Cloud Storage from Python 3? Eventually Python 2, if it's infeasible from Python 3.
I've looked and looked, but haven't found a solution that actually works. I tried boto, but when I try to generate the necessary .boto file through gsutil config -e
, it keeps saying that I need to configure authentication through gcloud auth login
. However, I have done the latter a number of times, without it helping.
A simple function to upload files to a gcloud bucket.
You can generate a credential file using this link: https://cloud.google.com/storage/docs/reference/libraries?authuser=1#client-libraries-install-python
Asynchronous Example:
Imports the Google Cloud client library (need credentials)
Instantiates a client
Use the standard gcloud library, which supports both Python 2 and Python 3.
Example of Uploading File to Cloud Storage
When installing Google Cloud Storage API:
pip install google-cloud
will throw a
ModuleNotFoundError
:Make sure you install as in Cloud Storage Client Libraries Docs:
pip install --upgrade google-cloud-storage