小编Gwe*_*en7的帖子

使用 Node.js 从 Google Cloud Platform 存储桶获取文件夹列表

我想在 Node.js 应用程序上显示 Google Cloud Storage 存储桶中的所有文件夹,但只有 getFiles() 函数。

例如,名为/abc的文件夹,其中有 2 个文件/a/b。我只想得到/abc/而没有/abc/a/abc/b

应用程序.js

router.get('/', async(req, res) => {
  let bucketName = 'my-bucket'

  const storage = Storage();

  const [files] = await storage.bucket(bucketName).getFiles();
  let app = [];
  for (const file of files) {
    const [metadata] = await file.getMetadata();
    app.push(metadata);
  };
  res.render('views/list.ejs', {
    apps : app, 
  });
  });
Run Code Online (Sandbox Code Playgroud)

google-app-engine node.js google-cloud-storage google-cloud-platform

5
推荐指数
1
解决办法
4026
查看次数