Skip to content

Instantly share code, notes, and snippets.

@Gabri3l
Created April 22, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gabri3l/92a5e2a5da79e49c4a54e968249325b0 to your computer and use it in GitHub Desktop.
Save Gabri3l/92a5e2a5da79e49c4a54e968249325b0 to your computer and use it in GitHub Desktop.
import tempfile
import json
from google.cloud import storage
def upload_from_temp_file(some_data):
with tempfile.NamedTemporaryFile() as fp:
json_data = json.dumps(some_data)
fp.write(json_data.encode())
fp.flush()
with open(fp.name, "rb") as f:
storage_client = storage.Client()
bucket = storage_client.get_bucket('my_bucket')
blob = bucket.blob("some_cool_name.json")
blob.upload_from_file(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment