cloudyr / aws.s3

Amazon Simple Storage Service (S3) API Client
https://cloud.r-project.org/package=aws.s3
381 stars 147 forks source link

put_acl deletes the content of the file when changing from a private to a public-read acl #391

Open MarcinKosinski opened 3 years ago

MarcinKosinski commented 3 years ago

Please specify whether your issue is about:

library(aws.s3)

# create a bucket
bucket_name <- 'test-r-package'
aws.s3::put_bucket(bucket_name)

# create a file for the upload
file_to_upload <- tempfile()
writeLines('A', file_to_upload)
file.size(file_to_upload)

# canned access control list
https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl

# upload with 'public-read' acl
put_object(
  file = file_to_upload, 
  object = 'public-read-file', 
  bucket = bucket_name, 
  acl = 'public-read' 
)

# upload with 'private' acl
put_object(
  file = file_to_upload, 
  object = 'private-file', 
  bucket = bucket_name, 
  acl = 'private' 
)

# get 'private' file and check the size
private_file <- aws.s3::get_object(object = 'private-file', bucket = bucket_name, as = 'raw')
writeLines(gsub('\r\n', '\n', rawToChar(private_file), fixed = TRUE), con = 'private_file')
# check file size
file.size('private_file')

# the issue ---------------------------------------------------------------

# ONCE YOU CHANGE ACL FROM 'private' TO 'public-read' THE BECOMES EMPTY

# make 'private' object a 'public-read' object
put_acl(
  object = 'private-file', 
  bucket = bucket_name, 
  acl = 'public-read' 
)

# get 'private' file and check the size
private_file <- aws.s3::get_object(object = 'private-file', bucket = bucket_name, as = 'raw')
writeLines(gsub('\r\n', '\n', rawToChar(private_file), fixed = TRUE), con = 'private_file')
# check file size
readLines('private_file')

## session info for your system
R version 4.0.1 (2020-06-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] aws.s3_0.3.21

loaded via a namespace (and not attached):
  [1] colorspace_2.0-0    ggsignif_0.6.0     
  [3] ellipsis_0.3.2      rio_0.5.16         
  [5] qdapRegex_0.7.2     rprojroot_2.0.2    
  [7] htmlTable_2.1.0     snakecase_0.11.0   
  [9] base64enc_0.1-3     fs_1.5.0           
 [11] gridtext_0.1.4      ggtext_0.1.1       
 [13] rstudioapi_0.13     ggpubr_0.3.0       
 [15] remotes_2.2.0       fansi_0.4.1        
 [17] lubridate_1.7.9.2   textclean_0.9.3    
 [19] xml2_1.3.2          g6tr_0.5.2         
 [21] splines_4.0.1       extrafont_0.17     
 [23] cachem_1.0.5        knitr_1.30         
 [25] pkgload_1.1.0       Formula_1.2-4      
 [27] broom_0.5.6         Rttf2pt1_1.3.8     
 [29] cluster_2.1.0       png_0.1-7          
 [31] compiler_4.0.1      httr_1.4.2         
 [33] backports_1.1.7     assertthat_0.2.1   
 [35] Matrix_1.2-18       fastmap_1.1.0      
 [37] cli_2.4.0           htmltools_0.5.1.1  
 [39] prettyunits_1.1.1   tools_4.0.1        
 [41] gtable_0.3.0        glue_1.4.2         
 [43] dplyr_1.0.6         Rcpp_1.0.5         
 [45] carData_3.0-4       cellranger_1.1.0   
 [47] vctrs_0.3.8         writexl_1.3        
 [49] nlme_3.1-148        extrafontdb_1.0    
 [51] xfun_0.24           stringr_1.4.0      
 [53] ps_1.4.0            openxlsx_4.1.5     
 [55] testthat_3.0.0      mime_0.9           
 [57] lifecycle_1.0.0     renv_0.13.1        
 [59] devtools_2.3.2      rstatix_0.6.0      
 [61] scales_1.1.1        g6tr.theme_0.1.8   
 [63] hms_0.5.3           RColorBrewer_1.1-2 
 [65] yaml_2.2.1          curl_4.3           
 [67] gridExtra_2.3       memoise_2.0.0      
 [69] aws.signature_0.6.0 ggplot2_3.3.2      
 [71] rpart_4.1-15        labelled_2.5.0     
 [73] latticeExtra_0.6-29 stringi_1.5.3      
 [75] desc_1.2.0          checkmate_2.0.0    
 [77] pkgbuild_1.1.0      zip_2.1.1          
 [79] rlang_0.4.11        pkgconfig_2.0.3    
 [81] evaluate_0.14       lattice_0.20-41    
 [83] purrr_0.3.4         htmlwidgets_1.5.2  
 [85] processx_3.4.5      tidyselect_1.1.0   
 [87] magrittr_2.0.1      R6_2.5.0           
 [89] generics_0.1.0      Hmisc_4.5-0        
 [91] DBI_1.1.0           mgcv_1.8-31        
 [93] pillar_1.6.1        haven_2.3.1        
 [95] foreign_0.8-80      withr_2.3.0        
 [97] nnet_7.3-14         survival_3.1-12    
 [99] abind_1.4-5         tibble_3.1.2       
[101] janitor_2.0.1       crayon_1.3.4       
[103] car_3.0-8           utf8_1.1.4         
[105] rmarkdown_2.9    

The size of the file for a private ACL

proper-size

The size of the file when ACL is changed to a public-read

empty-size

MarcinKosinski commented 3 years ago

cc @StefanMusch