Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcs_save_all does not allow setting predefined_acl #129

Closed
BrandonY opened this issue Oct 2, 2020 · 4 comments
Closed

gcs_save_all does not allow setting predefined_acl #129

BrandonY opened this issue Oct 2, 2020 · 4 comments

Comments

@BrandonY
Copy link

BrandonY commented Oct 2, 2020

It appears that the gcs_save_all() function defaults to setting a predefinedAcl of "private" when uploading, and it provides no option to override this setting.

For buckets with uniform bucket-level access enabled, "private" is not a valid predefinedAcl setting, and so there is no way to legally use gcs_save_all for such buckets, as a user noticed on Stack Overflow: https://stackoverflow.com/questions/64164389/uploading-png-images-to-gcs-in-r-can-upload-individually-but-cannot-upload-en

Solutions include changing the default behavior to not specifying an ACL or allowing the customer to override the default behavior.

@MarkEdmondson1234
Copy link
Collaborator

Thanks, uniform buckets are the norm now but object level ACL was legacy - this function did not get updated when the others did as well which was an oversight so will add an option to specify the ACL or use uniform bucket ACL.

@MarkEdmondson1234
Copy link
Collaborator

A workaround for now is to look at the function and modify it which is what the fix will be:

gcs_save_all <- function(directory = getwd(),
                         bucket = gcs_get_global_bucket(),
                         pattern = ""){

  tmp <- tempfile(fileext = ".zip")
  on.exit(unlink(tmp))

  bucket <- as.bucket_name(bucket)

  the_files <- list.files(path = directory,
                          all.files = TRUE,
                          recursive = TRUE,
                          pattern = pattern)
  
  withCallingHandlers(
    zip::zip(tmp, files = the_files),
    deprecated = function(e) NULL)

  gcs_upload(tmp, bucket = bucket, name = directory, predefinedAcl = "bucketLevel")

}

@MarkEdmondson1234
Copy link
Collaborator

MarkEdmondson1234 commented Oct 2, 2020

That should be fixed now, you can pass in the predefinedACl in gcs_save_all() so the below should work:

googleCloudStorageR::gcs_save_all(
  directory = 'path-to-all-images',
  bucket = 'my-bucket',
  predefinedAcl = "bucketLevel"
)

Use the GitHub version to use it e.g. install via remotes::install_github("cloudyr/googleCloudStorageR")

MarkEdmondson1234 added a commit that referenced this issue Oct 2, 2020
@BrandonY
Copy link
Author

BrandonY commented Oct 2, 2020

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants