Ero*_*ano 4 node.js firebase google-cloud-platform google-cloud-functions firebase-storage
如何使用 Firebase 函数在 Firebase 存储上上传包含 JSON 的新文件?到目前为止我的代码:
exports.scheduledFunctionCrontab = functions.pubsub.schedule("0 0 * * *")
.onRun(async () => {
try {
const response = await axios.get("api.com");
const bucket = await admin.storage().bucket();
// What now?
} catch (e) {
functions.logger.error(e);
}
return null;
})
Run Code Online (Sandbox Code Playgroud)
您可以将save()API 响应写入 JSON 文件,如下所示:
exports.scheduledFunctionCrontab = functions.pubsub.schedule("0 0 * * *")
.onRun(async () => {
try {
const response = await axios.get("api.com");
const bucket = await admin.storage().bucket();
const file = bucket.file("file.json");
const contents = JSON.stringify(data);
await file.save(contents);
} catch (e) {
functions.logger.error(e);
}
return null;
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
554 次 |
| 最近记录: |