Add Tag while uploading an object to Amazon s3 in rails

懵懂的女人 提交于 2019-12-23 01:28:28

问题


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"}

How can I add suitable tags (key-value pairs) -- for example exp: tag = { marked_to_delete: "true" } -- while uploading?


回答1:


You should be able to do that by passing tagging: "marked_to_delete=true" as an option.

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", 
})


来源:https://stackoverflow.com/questions/49047085/add-tag-while-uploading-an-object-to-amazon-s3-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!