簡體   English   中英

如何從雲存儲中獲取在某個時間創建的 Firebase 的文件?

[英]how to get files from Cloud Storage for Firebase that created at a certain time?

在此處輸入圖像描述

我需要刪除雲存儲中eventPoster文件夾中上次修改元數據超過 6 個月前的圖像。

所以我想使用 Cloud Function 進行 cron 作業,並且我需要“查詢”上次修改時間超過 6 個月的文件

如何使用管理員 SDK 做到這一點?

我想我找到了解決方案

根據這個答案,沒有辦法通過元數據查詢

所以,至於現在我使用下面的代碼來獲取過時的文件

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM