简体   繁体   English

如何使用 Google Cloud Storage Java SDK 获取存储桶中最后创建的文件?

[英]How to get last created file in a bucket using Google Cloud Storage Java SDK?

How do I get the last created file in a GCS bucket using Google Cloud Storage Java SDK?如何使用 Google Cloud Storage Java SDK 在 GCS 存储桶中获取最后创建的文件? Currently, I am using the storage.list() and iterating through all the files and thus getting the last created file.目前,我正在使用storage.list()并遍历所有文件,从而获取最后创建的文件。

Is there a better way of doing this?有没有更好的方法来做到这一点?

Cloud Storage doesn't offer flexible querying of objects. Cloud Storage 不提供灵活的对象查询。 If you want to find objects based on some property, such as upload time, you should store that information in a database whenever an object created, updated, or delete.如果要根据某些属性(例如上传时间)查找对象,则应在创建、更新或删除对象时将该信息存储在数据库中。 Then, you can just query the database to find what you want.然后,您可以查询数据库以找到您想要的内容。

You could write a cloud function which copies any uploaded file to a fixed key (listen on the finalize GCS event), say key 1. Then your application just queries key 1.您可以编写一个云函数,将任何上传的文件复制到一个固定的键(监听 finalize GCS 事件),比如键 1。然后您的应用程序只查询键 1。

Instead of copying the file you could also look at a peristent cache like Redis to store key 1.除了复制文件,您还可以查看像 Redis 这样的持久缓存来存储密钥 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 JAVA 中的谷歌存储云存储桶中获取所有 pdf 文件 - How to get all pdf file from google storage cloud bucket in JAVA 无法通过 java sdk 在谷歌云存储中连接和创建存储桶 - Unable to connect and create bucket in google cloud storage via java sdk 如何获取Google Cloud Storage中文件的上次修改日期? - How to get last modified date of a file in Google Cloud Storage? 将对象上传到Google Cloud Storage Bucket Java - Uploading objects to google cloud storage bucket java 如何使用Java在Google Cloud Storage中插入pdf文件 - How to insert a pdf file in Google Cloud Storage using Java 如何使用Java API更新Google Cloud Storage中文件的ACL - How to update ACL of a file in Google Cloud Storage using Java API 如何使用java上传谷歌云存储中的文件 - How to upload a file in the google cloud storage using java Google Cloud Storage使用Java上传文件 - Google Cloud Storage upload a file using java 如何设置pageToken以通过Java SDK从Google云端存储中获取项目列表? - How can I set pageToken to get item lists from Google Cloud Storage via Java SDK? 如何使用在Android Studio中创建的应用程序将文件上传到Google云端存储? - How do you upload a file using an app created in Android Studio to Google Cloud Storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM