0
votes

I am using the googlecloudstorageclient for manipulating files in a bucket. The bucket is not and should not be public readable, but I need to set public-read ({'x-goog-acl': 'public-read'}) for single files via python code.

How can I programmatically in python change the ACL or metadata on an existing GCS-file to public-read or remove that?

I tried copy2(), but it resets the content-type to binary/octet-stream if I pass in permissions.

https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions

2

2 Answers

0
votes

Use the listbucket method to iterate through the bucket and get the content-type from GCSFileStat for each file.

Now use the copy2 method and provide the metadata dict with the values from GCSFileStat and modify the ACL in that dict.

0
votes

You can use objects patch to change the acl or metadata of an object. This code example (using insert acl) shows you how to use the cloud storage apiclient and send an authorized api request using appengine.