Java 列出Google云存储桶中特定时间戳后更改的文件
我想列出在node.js中的特定时间戳之后在Google云存储桶中更改/添加的文件。我正在浏览文档,但没有找到任何机制Java 列出Google云存储桶中特定时间戳后更改的文件,java,node.js,google-cloud-platform,google-cloud-storage,google-cloud-functions,Java,Node.js,Google Cloud Platform,Google Cloud Storage,Google Cloud Functions,我想列出在node.js中的特定时间戳之后在Google云存储桶中更改/添加的文件。我正在浏览文档,但没有找到任何机制 const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); const bucketName = 'my-bucket'; const [files] = await storage.bucket(bucketName).getFiles(); 如何列出在bucket中的
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucketName = 'my-bucket';
const [files] = await storage.bucket(bucketName).getFiles();
如何列出在bucket中的时间戳之后添加的文件?对于给定的文件,这似乎是不可能的。文档中没有提到任何关于过滤带有日期的对象的内容
将所有上传文件的数据存储在数据库中是很常见的,这样更容易查询您想要存储的文件的任何属性。您甚至可以使用云函数触发器为每次文件上载自动将记录写入数据库。正如Doug Stevenson指出的那样,没有直接的函数可以这样做,但是您可以通过搜索文件的元数据来确知上次修改文件的时间。例如,请参见以下代码段:
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucketName = 'your-bucket-name';
storage.bucket(bucketName).getFiles(function(err, files) {
if (!err) {
// files is an array of File objects.
files.forEach(function (file){
file.getMetadata(function (err, metadata){
// TODO: Save only the files before certain metadata.updated date
console.log("File named " + metadata.name +
"last updated on: " + metadata.updated);
});
});
}
});
然后,您可以在
getMetadata
回调函数中创建一个条件,只列出/保留某个metadata.update
日期阈值之后的文件 对此没有直接的API支持。但是,如果您需要经常执行此查询,则可以手动构建工作流以保留索引。它将由一个小应用程序组成,其中存储一个订阅了关于bucket更改的通知的索引,并且它将有一个API方法来检索按日期排序的对象