首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从Google函数(Python)将一个新文件写入Google存储桶

从Google函数(Python)将一个新文件写入Google存储桶
EN

Stack Overflow用户
提问于 2020-01-18 11:03:17
回答 3查看 8.5K关注 0票数 4

我正在尝试从函数中编写一个新文件(而不是上传一个现有文件)到桶中。

F 211

任何想法都将不胜感激。

谢谢。

EN

Stack Overflow用户

发布于 2020-06-06 00:48:39

代码语言:javascript
运行
复制
 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()
票数 3
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59799941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档