代码之家  ›  专栏  ›  技术社区  ›  Vlad

R: 写入s3对象元数据

  •  0
  • Vlad  · 技术社区  · 7 年前

    我用的是R包 aws.s3

    下面的代码用于从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 回复  |  直到 7 年前
        1
  •  0
  •   Steven    7 年前

    两者兼而有之 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)