Get and put object tagging
Please specify whether your issue is about:
- [ ] a possible bug
- [ ] a question about package functionality
- [x] a suggested code or documentation change, improvement to the code, or feature request
I have objects in my S3 bucket that have object tags. I'd like to be able to put files back up there with tags as well. It would be fab if functionality for getting object tags (not just bucket tags), and putting object tags was included in your package.
Agreed, this looks like it would be pretty easy to add in:
https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectTagging.html
While this is possible using paws, I did not want to introduce extra dependencies in my current code that works with aws.s3. Hence I have found a workaround after some searching (only depends on xml2, which is already an aws.s3 dependency) that works with s3HTTP. The region needs to be specified otherwise the code doesn't work. I have set verbose=TRUE if this wouldn't work on your system to get extra info.
Getting object tagging can be obtained using:
gettags <- s3HTTP(verb = "GET",
bucket = "<bucket_name>",
path = "<object_key>",
query = list(tagging = ""),
verbose = TRUE,
region="<bucket_aws_region>")
Putting a single tag, in this case "TAG_KEY"="TAG_VALUE" is a bit more complex:
settags <- s3HTTP(verb = "PUT",
bucket = "<your_bucket>",
path = "<your_object>",
query = list(tagging = ""),
request_body = as.character(as_xml_document(list(Tagging = list(TagSet = list(Tag = list(Key=list("TAG_KEY"),Value=list("TAG_VALUE"))))))),
verbose = TRUE,
region="<bucket_aws_region>")
I have not yet tested putting more than one tag key/value pair, but R lists do not need unique names for their elements so you could set the inner Tag element multiple times.
Normally, I would open a PR for this, but it appears PR's are not merged anymore - and looking at the amount of forks a lot of people are just developing their own version of this package.