R:写入s3对象元数据

时间:2018-12-08 00:09:17

标签: r amazon-s3

我在Amazon Web Services上将R软件包aws.s3与S3存储桶一起使用。有没有办法为R中的存储桶对象编写元数据?

下面的代码用于从S3读取元数据。

library(aws.s3)
head_object("my_object", bucket = "my_bucket")

[1] TRUE
attr(,"x-amz-id-2")
[1] "abc"
attr(,"x-amz-request-id")
[1] "abc"
attr(,"date")
[1] "Sat, 08 Dec 2018 00:01:34 GMT"
attr(,"last-modified")
[1] "Fri, 07 Dec 2018 20:45:47 GMT"
attr(,"etag")
[1] "\"abc\""
attr(,"x-amz-meta-source-info")
[1] "how can I write this from R?"  <---- created meta data in AWS console
attr(,"accept-ranges")
[1] "bytes"
attr(,"content-type")
[1] "application/zip"
attr(,"content-length")
[1] "100"
attr(,"server")
[1] "AmazonS3"

1 个答案:

答案 0 :(得分:0)

put_object()save_object()都有一个名为headers的参数。这就是s3_object的元数据的去向。 AWS suggests that custom metadata tags need to be prefixed by x-amz-meta-,并且需要具有匹配的值。

创建键和值的列表然后进行匹配可能是最简单的方法:

keys <- list("key1", "key2")
values <- list("unlock", "does-not-unlock")

keys <- lapply(function(x) paste0("x-amz-meta-", x))

metadata <- setNames(values, keys)

put_object(file, object, bucket, headers = metadata)