首页 > 解决方案 > 如何使用 Node.JS 从 GCS 存储桶中读取删除的过期时间?

问题描述

我已将 GCS 存储桶配置为在 20 天后自动删除存储在其中的对象(通过 GCP Web UI 执行此操作)。当我在 Node.JS 中引用存储桶对象时,如何获取它配置为老化的天数?

GCS 生命周期参考在这里,但不提供示例。

标签: node.jsgoogle-cloud-platformgoogle-cloud-storage

解决方案


您是否尝试过使用addLifecycleRule方法并设置存储桶策略?

@example
     * const {Storage} = require('@google-cloud/storage');
     * const storage = new Storage();
     * const bucket = storage.bucket('bucket-name');
     *
     * //-
     * // Automatically have an object deleted from this bucket
     * // of age.
     * //-
     * bucket.addLifecycleRule({
     *   action: 'delete',
     *   condition: {
     *     age: 20 // Specified in days.
     *   }
     * }, function(err, apiResponse) {
     *   if (err) {
     *     // Error handling omitted.
     *   }


推荐阅读