在rails中将对象上传到Amazon s3时添加Tag

我正在尝试将CS​​V文件上传到Amazon S3。

我可以使用下面的代码片段添加元数据:

s3_obj.upload_file(file_to_be_uploaded, {"content_type": "application/octet-stream"} 

如何在上传时添加合适的标签(键值对) – 例如exp: tag = { marked_to_delete: "true" }

您应该可以通过传递tagging: "marked_to_delete=true"来做到这一点tagging: "marked_to_delete=true"作为选项。

选项被传递给AWS::S3::Clientput_object方法的实例。 文档给出了一个类似的例子 :

 resp = client.put_object({ body: "filetoupload", bucket: "examplebucket", key: "exampleobject", server_side_encryption: "AES256", tagging: "key1=value1&key2=value2", })