来自 GCS 的事件对象列表

问题描述 投票:0回答:1

我们有一个存储桶,其中有 40 多个对象。我们希望读取每个对象,从列中提取特定数据并将它们存储为单独的文件。

如何获取所有这些对象列表并处理每个对象?我们可以在 pub/sub 中获取这个对象列表吗

google-cloud-storage
1个回答
0
投票

您没有指定很多详细信息,因此请指定以下内容。 1.用什么语言。 2.要提取什么类型的数据以及您想要在哪里/如何保存/存储它们(如果/或任何特定的文件格式)。

同时这是一个简单的代码片段。

exports.iterateThroughFiles = functions.https.onRequest(async (req, res) => {
  try {
    const bucketName = 'your-bucket-name';
    const bucket = storage.bucket(bucketName);

    const [files] = await bucket.getFiles();

    files.forEach((file) => {
      // Perform operations on each file
      console.log(`File name: ${file.name}`);
    });

    res.status(200).send('Files iteration completed successfully.');
  } catch (error) {
    console.error('Error iterating through files:', error);
    res.status(500).send('An error occurred while iterating through files.');
  }
});

如果是这样,那么就可以了,但是对于任何特定的方法要求。更多澄清。

© www.soinside.com 2019 - 2024. All rights reserved.