python-3.x - 直接到烧瓶中的 Google 存储桶
问题描述
我分享了将文件上传到 gcp 存储桶而不在本地保存文件的解决方案。
from google.cloud import storage
@app.route('/upload/', methods=['POST'])
def upload():
if request.method == 'POST':
# FileStorage object wrapper
file = request.files["file"]
if file:
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = app.config['GOOGLE_APPLICATION_CREDENTIALS']
bucket_name = "bucket_name"
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
# Upload file to Google Bucket
blob = bucket.blob(file.filename)
blob.upload_from_string(file.read())
解决方案
推荐阅读
- ios - 更新 pod 后 FirebaseApp.configure() 崩溃
- spring-boot - 弹簧靴中的可选课程?
- c# - 如何获取选中按钮的内容
- java - Java,使用扫描仪时如何验证输入?
- android - E/SQLiteLog: (1) no such table: Cars on Android 9 Pie
- xcode - 对包含 .app 的 .zip 进行公证和装订的最有效方法是什么?
- iqueryable - Automapper Queryable Extensions 没有出现
- bash - 如何通过 Bash 中的 curl 从谷歌驱动器下载大文件?
- java - Spring Boot 获取 Api 响应:Ebay API
- javascript - 如何根据单击的图像更新内容(Angular)