How to set TTL on a Blob in Google Cloud Storage using Java?

坚强是说给别人听的谎言 提交于 2019-12-02 07:17:12

问题


Using Java, is it possible to set the time to live (TTL) on a blob that is being created in Google Cloud Storage?

I do not want to set TTL on the Bucket - only on the items within the Bucket.

For example, 14 days after its creation date, I would like any files that are stored in a specific bucket to be deleted.

Here is an example of how I am creating my blob: WriteChannel writer = storage.writer(BlobInfo.newBuilder(blobId).setContentType("application/json").build());

I was looking for a way to set the TTL upon creation but have not been able to find a solution. Please advise


回答1:


It is not currently possible to set a per-object TTL, you can only configure a bucket-wide TTL that applies to all objects in the bucket by setting the buckets LifeCycle configuration. https://cloud.google.com/storage/docs/lifecycle

Setting a TTL of 14 days on the bucket via LifeCycle will not cause the bucket itself to be deleted after 14 days, instead it will cause each object uploaded to that bucket to be deleted 14 days after it was created.



来源:https://stackoverflow.com/questions/45602867/how-to-set-ttl-on-a-blob-in-google-cloud-storage-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!