在Rails中将对象上传到Amazon s3时添加标签 [英] Add Tag while uploading an object to Amazon s3 in rails
本文介绍了在Rails中将对象上传到Amazon s3时添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将CSV文件上传到Amazon S3.
I'm trying to upload CSV files to Amazon S3.
我可以使用以下代码段添加元数据:
I'm able to add metadata using the below code snippet:
s3_obj.upload_file(file_to_be_uploaded, {"content_type": "application/octet-stream"}
如何在上传时添加合适的标签(键值对)(例如exp: tag = { marked_to_delete: "true" }
)?
How can I add suitable tags (key-value pairs) -- for example exp: tag = { marked_to_delete: "true" }
-- while uploading?
推荐答案
您应该可以通过将tagging: "marked_to_delete=true"
作为选项来做到这一点.
You should be able to do that by passing tagging: "marked_to_delete=true"
as an option.
选项被传递到AWS::S3::Client
的put_object
方法的实例.该文档给出了类似的
Options are passed to an instance of AWS::S3::Client
's put_object
method. The docs give a similar example:
resp = client.put_object({
body: "filetoupload",
bucket: "examplebucket",
key: "exampleobject",
server_side_encryption: "AES256",
tagging: "key1=value1&key2=value2",
})
这篇关于在Rails中将对象上传到Amazon s3时添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文