R2 object creation and modification dates

How can I get and set R2 metadata like creation and modification dates?

You can retrieve metadata about R2 objects via the head, get and list methods, depending on what you want to do. For example: const object = await R2_BUCKET.head('foobar'). This will then contain properties like uploaded and any custom metadata you may have set via the put method for the object named foobar.

For more information, see the Runtime APIs section in the R2 docs: https://developers.cloudflare.com/r2/runtime-apis

1 Like

Thanks. Does this mean R2 does not natively have a modification date metadata?

It’ll appear the same as any other S3 API would display it - i.e with aws-sdk-php

// array(1) {
//   [0]=>
//   array(5) {
//     ["Key"]=>
//     string(14) "ferriswasm.png"
//     ["LastModified"]=>
//     object(Aws\Api\DateTimeResult)#187 (3) {
//       ["date"]=>
//       string(26) "2022-05-18 17:20:21.670000"
//       ["timezone_type"]=>
//       int(2)
//       ["timezone"]=>
//       string(1) "Z"
//     }
//     ["ETag"]=>
//     string(34) ""eb2b891dc67b81755d2b726d9110af16""
//     ["Size"]=>
//     string(5) "87671"
//     ["StorageClass"]=>
//     string(8) "STANDARD"
//   }
// }

Oh, thanks but I just using the plain R2 api (not the S3 api), and couldn’t see any metadata associated

Turns out that uploaded in the R2 object and any LastModified date from an API or the dashboard are the same thing.

image
image

1 Like