python-3.x - 使用 Pyrebase 从 Google App Engine 将 JSON 文件上传到 Firebase 存储
问题描述
我有一个在 GAE 中运行的非常简单的 Flask Web 应用程序,它从 Firebase 存储下载一个 JSON 文件,并在必要时用更新的文件替换它。一切正常,但每当我尝试创建新文件时,GAE 都会引发 IOError 异常。我正在使用 Firebase 存储,因为我知道在 GAE 环境中无法读取/写入文件,但是我应该如何使用 Pyrebasestorage.child('foo.json').put('foo.json')
函数呢?我做错了什么?请在下面检查我的代码。
firebase_config = {my_firebase_config_dict}
pyrebase_app = pyrebase.initialize_app(firebase_config)
storage = pyrebase_app.storage()
@app.route('/')
def check_for_updates() :
try :
json_feeds = json.loads(requests.get('http://my-firebase-storage-url/example.json').text()
# Here I check if I need to update example.json
# ...
with open("example.json", "w") as file:
json.dump(info, file)
file.close()
storage.child('example.json').put('example.json')
return 'finished successfully!'
except IOError :
return 'example.json doesn't exists'
解决方案
如果我理解正确,您只需要在 GAE 中临时使用此文件,然后将其放入云存储中。根据此文档,您可以像在普通操作系统中一样执行此操作,但在 /tmp 文件夹中:
如果您的应用只需要写入临时文件,您可以使用标准 Python 3.7 方法将文件写入名为 /tmp 的目录
我希望它会有所帮助!
推荐阅读
- asp.net-core - 网站页面之间的即时转换
- php - 对于 Shopify,我在学习 PHP 或 Ruby 之间存在冲突
- sql - MS Access VBA SQL SELECT * INTO tempTbl WHERE Stuff="" AND OtherStuff BETWEEN Date Range
- java - 是否可以使用通配符创建路由?
- python - 如何在 Python 中对幻数进行 lint(静态分析代码)?
- database - 如何验证我的 sqlite3 数据库是 3.25 版?
- amazon-web-services - 来自账户拥有的任何存储桶的 S3 跨账户通知
- javascript - Angular 6 动画转发(Angular 中的动画填充模式)
- java - 如何“跳过”一条规则以支持一条规则而不是另一条规则?
- go - 如何避免翻译舵图的一些`{{`?