Google Cloud Storage NodeJS 和 JSON API 在尝试列出时不返回某些文件夹
Google Cloud Storage NodeJS and JSON API not returning certain folders when trying to list
尝试使用 NodeJS 客户端库时(getFiles -
https://googleapis.dev/nodejs/storage/latest/Bucket.html#getFiles)
和 JSON API (objects/list - https://cloud.google.com/storage/docs/json_api/v1/objects/list) 在这两种情况下,响应似乎都不是 return 某些文件夹。
使用 gsutil ls
时它会按预期列出所有文件夹,使用 Google 云控制台浏览 GCS 存储桶时也会按预期列出所有文件。
存储中是否有变化 API 可能导致这种情况发生?
更新:
使用 NodeJS Client SDK for Storage 列出 GCS 文件夹路径的代码:
import * as functions from 'firebase-functions';
import { Storage } from '@google-cloud/storage';
import { globVars } from '../admin/admin';
const projectId = process.env.GCLOUD_PROJECT;
// shared global variables setup
const { keyFilename } = globVars;
// Storage set up
const storage = new Storage({
projectId,
keyFilename,
});
export const gcsListPath = functions
.region('europe-west2')
.runWith({ timeoutSeconds: 540, memory: '256MB' })
.https.onCall(async (data, context) => {
if (context.auth?.token.email_verified) {
const { bucketName, prefix, pathList = false, fileList = false } = data;
let list;
const options = {
autoPaginate: false,
delimiter: '',
prefix,
};
if (pathList) {
options.delimiter = '/';
const verboseResponse = await storage
.bucket(bucketName)
.getFiles(options);
list = verboseResponse[2].prefixes;
}
if (fileList) {
const [files] = await storage
.bucket(bucketName)
.getFiles(options);
list = files.map((file) => file.name);
}
return { list };
} else {
return {
error: { message: 'Bad Request', status: 'INVALID_ARGUMENT' },
};
}
});
分页功能似乎限制了结果。实施 nextQuery
returns下一页列表。
尝试使用 NodeJS 客户端库时(getFiles -
https://googleapis.dev/nodejs/storage/latest/Bucket.html#getFiles)
和 JSON API (objects/list - https://cloud.google.com/storage/docs/json_api/v1/objects/list) 在这两种情况下,响应似乎都不是 return 某些文件夹。
使用 gsutil ls
时它会按预期列出所有文件夹,使用 Google 云控制台浏览 GCS 存储桶时也会按预期列出所有文件。
存储中是否有变化 API 可能导致这种情况发生?
更新:
使用 NodeJS Client SDK for Storage 列出 GCS 文件夹路径的代码:
import * as functions from 'firebase-functions';
import { Storage } from '@google-cloud/storage';
import { globVars } from '../admin/admin';
const projectId = process.env.GCLOUD_PROJECT;
// shared global variables setup
const { keyFilename } = globVars;
// Storage set up
const storage = new Storage({
projectId,
keyFilename,
});
export const gcsListPath = functions
.region('europe-west2')
.runWith({ timeoutSeconds: 540, memory: '256MB' })
.https.onCall(async (data, context) => {
if (context.auth?.token.email_verified) {
const { bucketName, prefix, pathList = false, fileList = false } = data;
let list;
const options = {
autoPaginate: false,
delimiter: '',
prefix,
};
if (pathList) {
options.delimiter = '/';
const verboseResponse = await storage
.bucket(bucketName)
.getFiles(options);
list = verboseResponse[2].prefixes;
}
if (fileList) {
const [files] = await storage
.bucket(bucketName)
.getFiles(options);
list = files.map((file) => file.name);
}
return { list };
} else {
return {
error: { message: 'Bad Request', status: 'INVALID_ARGUMENT' },
};
}
});
分页功能似乎限制了结果。实施 nextQuery
returns下一页列表。