如何使用Node.js获取Google Cloud Storage文件夹中的文件列表?
使用bucket.getFiles()
可以将所有文件存储在存储桶中.
Using bucket.getFiles()
it is possible to get all the files in a bucket.
我的存储桶中有成千上万个文件,我真的只想获取特定文件夹中文件的元数据.
My bucket has thousands of files and I really only want to get metadata on the files in a particular folder.
文档不清楚如何只从文件夹中获取文件.显然,可以用以下方式限制结果: GetFilesRequest
,但没有一个选项包含路径或文件夹,至少没有明确显示.
The documentation is not clear on how to just get the files from a folder. Apparently it is possible to limit the results with a GetFilesRequest
but none of the options include a path or a folder, at least not explicitly.
Google云存储没有文件夹/子目录.这是在平面名称空间之上的一种幻觉.即您看到的子目录实际上是名称中带有"/"字符的对象.
Google cloud storage doesn't have folders/sub directories. It is an illusion on top of the flat namespace. i.e what you see as sub directories are actually objects which has a "/" character in its name.
您可以通过以下链接详细了解Google云存储子目录的工作方式 https ://cloud.google.com/storage/docs/gsutil/addlhelp/HowSubdirectoriesWork
You can read more about how Google cloud storage subdirectories work at the following link https://cloud.google.com/storage/docs/gsutil/addlhelp/HowSubdirectoriesWork
因此,通过将GetFilesRequest
的prefix
参数设置为您感兴趣的子目录名称,将返回您要查找的对象.
So by setting the prefix
parameter of GetFilesRequest
to the sub directory name you are interested in will return the object you are looking for.