以下是使用官方云存储库进行访问的另一种方法:
# Import the Google Cloud client library and JSON library
from google.cloud import storage
import json
# Instantiate a Google Cloud Storage client and specify required bucket and file
storage_client = storage.Client()
bucket = storage_client.get_bucket('bucket_name')
blob = bucket.blob('filename.json')
# Download the contents of the blob as a string and then parse it using json.loads() method
data = json.loads(blob.download_as_string(client=None))
,
此方法使用 GCS 文件系统 gcsfs
可用于从 Google Cloud 存储读取文件。
# Reading gcs files with gcsfs
import gcsfs
import json
gcs_file_system = gcsfs.GCSFileSystem(project="gcp_project_name")
gcs_json_path = "gs://bucket_name/path/to/file.json"
with gcs_file_system.open(gcs_json_path) as f:
json_dict = json.load(f)
此方法也适用于 图像 存储在 GCS 中的 skimage
as,
from skimage import io
with gcs_file_system.open(gcs_img_path) as f:
img = io.imread(f)
本文链接:https://www.f2er.com/3160898.html