简体   繁体   English

如何使用Ruby SDK在AWS S3对象上设置Access-Control-Allow-Origin标头?

[英]How to set the Access-Control-Allow-Origin header on an AWS S3 object using Ruby SDK?

How do you set the Access-Control-Allow-Origin header of an S3 object using version 1 of the AWS SDK for Ruby. 如何使用适用于Ruby的AWS开发工具包的版本1设置S3对象的Access-Control-Allow-Origin标头。 The docs here show how to set a variety of headers, but there doesn't seem to be anything for the access control header. 此处文档显示了如何设置各种标头,但访问控制标头似乎没有任何内容。 It does mention a :metadata option, but that prefixes the values with x-amz-meta , which is not what I'm looking for. 它的确提到了:metadata选项,但是该值以x-amz-meta ,这不是我想要的。

The reason I ask is because I'm trying to download a publicly readable file in S3 (which I put there) by making an Ajax call from Javascript. 我问的原因是因为我试图通过从Javascript进行Ajax调用来下载S3中的公共可读文件(放置在该文件中)。 I have set the ACL to public read, which means I can view it in a browser, but I get the No 'Access-Control-Allow-Origin' header is present on the requested resource error from the Ajax call. 我已经将ACL设置为公共读取,这意味着我可以在浏览器中查看它,但是在Ajax调用No 'Access-Control-Allow-Origin' header is present on the requested resource错误中,我No 'Access-Control-Allow-Origin' header is present on the requested resource

Well, is that the only way to do it? 好吧,这是唯一的方法吗?

Yes, that's the only way to do it. 是的,那是唯一的方法。 CORS in S3 is only configurable at the bucket level. S3中的CORS只能在存储桶级别进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails Asset Pipeline:在开发中提供字体时如何设置Access-Control-Allow-Origin标头? - Rails Asset Pipeline: How to set the Access-Control-Allow-Origin header when serving fonts in development? 如何在Ruby中的API响应中添加“ Access-Control-Allow-Origin”标头 - How to add “Access-Control-Allow-Origin” headers to API Response in Ruby 无法为Spree API设置“ Access-Control-Allow-Origin” - Unable to set 'Access-Control-Allow-Origin' for Spree API Amazon S3:使用aws-sdk-ruby设置权限 - Amazon S3: set permissions using aws-sdk-ruby 请求的资源上没有“Access-Control-Allow-Origin”标头 - Rails 4.2 - No 'Access-Control-Allow-Origin' header is present on the requested resource - Rails 4.2 使用Ruby aws-sdk选择并使用AWS s3对象密钥的一部分 - Select and use part of an AWS s3 object key using Ruby aws-sdk 使用aws-sdk - > 2和ruby更改s3文件访问权限 - Change s3 file access with aws-sdk -> 2 and ruby 使用机架发送两个相同的标头(Access-Control-Allow-Origin) - Send two identical headers with Rack (Access-Control-Allow-Origin) 如何从公用文件夹中提供字体,以允许Rails中的“ Access-Control-Allow-Origin”? - How to serve fonts from public folder allowing “Access-Control-Allow-Origin” in rails? Amazon S3:如何在ruby AWS SDK中设置使用虚拟主机的请求 - Amazon S3: how to set requests to use virtual host in ruby aws sdk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM