Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Size of file/object in S3 bucket

Tags:

r

amazon-s3

I'm aware that an object can be read from S3 using aws.s3 library in R. How do I find object size without reading it into R?

like image 615
Ashrith Reddy Avatar asked Oct 17 '22 06:10

Ashrith Reddy


1 Answers

You may try using the head_object function from the aws.s3 package:

head_object(object, bucket, ...)

head_object checks whether an object exists by executing an HTTP HEAD request; this can be useful for checking object headers such as “content-length” or “content-type”.

If you poke around the AWS documentation for the HEAD object, you will see that a HEAD request is identical to a full GET request, except that the body will be empty. But, the content length header should be there, ideally telling you how large the object is. This information should be available in the returned R object.

like image 98
Tim Biegeleisen Avatar answered Oct 19 '22 11:10

Tim Biegeleisen