如何解决尝试列出
在尝试使用 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) 在这两种情况下,响应似乎都没有返回某些文件夹。
在使用 gsutil ls
时,它会按预期列出所有文件夹,而使用 Google Cloud Console 浏览 GCS 存储桶也会按预期列出所有文件。
Storage API 是否发生了可能导致这种情况发生的变化?
更新:
列出 GCS 文件夹路径的代码,使用 NodeJS Client SDK 进行存储:
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: '',};
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
返回下一页列表。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。