Rails - Upload private file to Google Cloud Storage

571 views Asked by At

I am working on a Rails project and the uploaded files are being stored in Google's Cloud Storage (via Fog). Every file that is uploaded by default has the "Public Link" checkbox checked and the two permissions are for the owner as "Owner" and for "allUsers" as "Reader" (I viewed these settings through the Google Dev Console).

I would like to make it so that when a user uploads an attachment the default is actually for the "Public Link" checkbox to be unchecked and for there to be no permissions for "allUsers". Is this possible?

2

There are 2 answers

0
Isaac On BEST ANSWER

For the :has_attached_file options, I added this:

:fog_public => false
0
Mike Schwartz On

Yes - you can accomplish this by changing the default object ACL on the bucket. You can do this with a gsutil command like:

gsutil defacl ch -d allUsers gs://your-bucket

This will remove the allUsers:R grant on the bucket's default object ACL, and objects uploaded after this point will not be publicly readable.

If you want to see the bucket's default object ACL before or after running this command, you can do:

gsutil defacl get gs://your-bucket