Javascript 获取由onFinalize触发的firebase云函数中已创建文件的同级

Javascript 获取由onFinalize触发的firebase云函数中已创建文件的同级,javascript,firebase,vue.js,google-cloud-platform,google-cloud-functions,Javascript,Firebase,Vue.js,Google Cloud Platform,Google Cloud Functions,我有一个云函数,在firebase存储中创建新文件时触发。在这个函数逻辑中,我需要收集数组中位于同一路径的所有其他文件。但我不知道怎么做 exports.testCloudFunc = functions.storage.object().onFinalize(async object => { const filePath = object.name; const { Logging } = require('@google-cloud/logging'); consol

我有一个云函数,在firebase存储中创建新文件时触发。在这个函数逻辑中,我需要收集数组中位于同一路径的所有其他文件。但我不知道怎么做

exports.testCloudFunc = functions.storage.object().onFinalize(async object => {
  const filePath = object.name;

  const { Logging } = require('@google-cloud/logging');

  console.log(`Logged: ${filePath}`);
  let obj = JSON.stringify(object);
  console.log(`Logged: ${obj}`);
});
之后,我将尝试将所有PDF合并到一个新文件中,并通过相同的路径将其保存回firebase存储。非常感谢您的帮助!提前感谢您的智慧)

根据Doug Stevenson链接(Node.js的第二个代码示例),您可以使用前缀和分隔符列出bucket中指定文件夹中的对象

上述文档中的样本

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const bucketName = 'Name of a bucket, e.g. my-bucket';
// const prefix = 'Prefix by which to filter, e.g. public/';
// const delimiter = 'Delimiter to use, e.g. /';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function listFilesByPrefix() {
  /**
   * This can be used to list all blobs in a "folder", e.g. "public/".
   *
   * The delimiter argument can be used to restrict the results to only the
   * "files" in the given "folder". Without the delimiter, the entire tree under
   * the prefix is returned. For example, given these blobs:
   *
   *   /a/1.txt
   *   /a/b/2.txt
   *
   * If you just specify prefix = '/a', you'll get back:
   *
   *   /a/1.txt
   *   /a/b/2.txt
   *
   * However, if you specify prefix='/a' and delimiter='/', you'll get back:
   *
   *   /a/1.txt
   */
  const options = {
    prefix: prefix,
  };

  if (delimiter) {
    options.delimiter = delimiter;
  }

  // Lists files in the bucket, filtered by a prefix
  const [files] = await storage.bucket(bucketName).getFiles(options);

  console.log('Files:');
  files.forEach(file => {
    console.log(file.name);
  });
}

listFilesByPrefix().catch(console.error);


这是否意味着首先返回所有文件,然后 是否按前缀过滤

正如我在上面的代码示例中看到的,数组[files]将存储已经通过筛选要求的对象:

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

使用云存储列表API列出具有公共路径前缀的文件。非常感谢。我发现我可以像这样收集所有文件:const[files]=await storage.bucket(bucketName.getFiles();但是如何指定“bucketName/loads/”这样的路径呢?请看文档中的第二个代码示例。这是否意味着首先返回所有文件,然后按前缀进行过滤?