![](/img/trans.png)
[英]How to get object from Cloud Storage for Firebase using Cloud Function?
[英]how to get files from Cloud Storage for Firebase that created at a certain time?
我想我找到了解決方案
根據這個答案,沒有辦法通過元數據查詢
所以,至於現在我使用下面的代碼來獲取過時的文件
import * as admin from "firebase-admin";
import * as moment from "moment";
const app = admin.initializeApp(); // I am using Google Cloud Function, much more simple to initialize the app
const bucket = app.storage().bucket();
const response = await bucket.getFiles({prefix: "eventPoster/"}); // set your folder name in prefix here
const files = response[0];
const sixMonthAgo = moment().subtract(6, "months").toDate();
const outOfDateFiles = files.filter((file) => {
const createdTime = new Date(file.metadata.timeCreated);
return moment(createdTime).isBefore(sixMonthAgo);
});
console.log(`number of outdated files: ${outOfDateFiles.length}`);
閱讀此處的文檔以進一步閱讀
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.