how to get file metadata from GCS

…衆ロ難τιáo~ 提交于 2021-01-28 11:13:38

问题


I would like to get file meta data of file stored in Google Cloud Storage. Actually we require a media link of file so file can be downloaded or url added to page for download.

Blob blob = storage.get("gcp-public-data-nexrad-l2", "1991/06/05/KTLX/NWS_NEXRAD_NXL2LG_KTLX_19910605160000_19910605235959.tar");
ReadChannel readChannel = blob.reader();
System.out.println(blob);

I am using public bucket, for example, but blob contains metadata=null. Is there any way to get file metadata?

Thanks


回答1:


GCP Support here! I tested the code and it’s working fine. The thing is that when you search for an object metadata it returns the bucket’s object metadata, not the file metadata itself.

You can make a quick test by going to the bucket and adding metadata to the object. To do so, you need to click on the three vertical dots icon of a file and edit metadata. Then you can run the code and you’ll see under "metadata" all the values you just added.

Here’s a useful doc about it.



来源:https://stackoverflow.com/questions/49683255/how-to-get-file-metadata-from-gcs

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