Last active
April 5, 2022 16:21
-
-
Save shikanime/20f8260772e866a5f9b3d5439a91b81d to your computer and use it in GitHub Desktop.
Stream request body to Google Cloud Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil | |
from google.cloud import storage | |
from google.cloud.storage.blob import BlobWriter | |
import urllib.request | |
with urllib.request.urlopen("https://jsonplaceholder.typicode.com/todos/1") as f: | |
storage_client = storage.Client() | |
bucket = storage_client.get_bucket("cel-em-gcs-dpf-ing-01-dev") | |
blob = bucket.blob("foo.txt") | |
blob_file = blob.open(mode="wb", content_type="text/plain") | |
assert type(blob_file) is BlobWriter | |
shutil.copyfileobj(f, blob_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[tool.poetry] | |
name = "request_to_gcs" | |
version = "0.1.0" | |
description = "" | |
authors = ["Shikanime Deva <deva.shikanime@protonmail.com>"] | |
[tool.poetry.dependencies] | |
python = "^3.9" | |
google-cloud-storage = "^2.2.1" | |
[tool.poetry.dev-dependencies] | |
black = "^22.3.0" | |
[build-system] | |
requires = ["poetry-core>=1.0.0"] | |
build-backend = "poetry.core.masonry.api" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment