我正在尝试从函数中编写一个新文件(而不是上传一个现有文件)到桶中。
google-cloud-storage,但它没有用于存储桶的"open“属性。GoogleAppEngineCloudStorageClient,但该函数无法与此gcs-client,但由于需要JSON文件,因此无法传递函数内部的凭据。F 211
任何想法都将不胜感激。
谢谢。
发布于 2020-06-06 00:48:39
from google.cloud import storage
import io
# bucket name
bucket = "my_bucket_name"
# Get the bucket that the file will be uploaded to.
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket)
# Create a new blob and upload the file's content.
my_file = bucket.blob('media/teste_file01.txt')
# create in memory file
output = io.StringIO("This is a test \n")
# upload from string
my_file.upload_from_string(output.read(), content_type="text/plain")
output.close()
# list created files
blobs = storage_client.list_blobs(bucket)
for blob in blobs:
print(blob.name)
# Make the blob publicly viewable.
my_file.make_public()https://stackoverflow.com/questions/59799941
复制相似问题