I am trying to check if a file exists on s3 through Rstudio on Amazon EC2 instance. Base R's exists()
function and file.exists()
functions are returning FALSE
for every file. Following is my code, exists.type
exists in s3 and not_exists.type
does not exist.
library("aws.s3")
Sys.setenv("AWS_ACCESS_KEY_ID" = "key1",
"AWS_SECRET_ACCESS_KEY" = "key2",
"AWS_DEFAULT_REGION" = "key3"
)
existing_file_path = "s3://bucket_name/folder_name/exists.type"
not_existing_file_path = "s3://bucket_name/folder_name/not_exists.type"
exists(existing_file_path) #returns FALSE
exists(not_existing_file_path) #returns FALSE
file.exists(existing_file_path) returns FALSE
file.exists(not_existing_file_path) returns FALSE
aws.s3::get_object(existing_file_path) #reads the entire file
aws.s3::get_object(not_existing_file_path) #gives error
I tried list.files
also, it returns character(0)
.
您应该使用函数head_object()
,该函数仅返回有关您对象的元数据,而不返回对象本身。
aws.s3::head_object("your_file", bucket = "your_bucket")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.