0

I want to set metadata all object when created date is on 12 o'clock tonight. For now I just can set metadata for all objects that's already in a bucket with this command below :

gsutil -m setmeta -h "Content-Type:application/pdf" -h "Content-disposition: inline"  gs://mystorage/pdf/*.pdf

My plan is to set all new object by run gsutil command in the midnight automatically because I already make a command witch upload all file from my server to google storage every midnight. But the only problem is I don't know witch file is new.

I know that we can use google cloud trigger but I just want to use gsutil command if it's possible

2 Answers2

0

I think there is no feature that gsutil or the GCS API provides to set metadata for objects based on timestamp.

According to link At upload time you can specify one or more metadata properties to associate with objects.

As you mentioned I already make a command which uploads all files from my server to google storage every midnight you can set metadata while uploading objects. command may look like below in your case.

gsutil -m setmeta -h "Content-Type:application/pdf" -h "Content-disposition: inline"  cp -r images gs://bucket/images

Or else

you can list the objects based on timestamp and store the output to a file. By iterating through each line in the outfile file use your setmetadata command for the objects.

0

Or, you can use Pub/Sub notifications for Cloud Storage, and subscribe to the new objects event OBJECT_FINALIZE.

Some sample code showing this can be referred here

Gourav B
  • 864
  • 5
  • 17