允许AJAX从Amazon S3 GET的? (访问控制 - 允许 - 产地) [英] Allow AJAX GETs from Amazon S3? (Access-Control-Allow-Origin)

查看:167
本文介绍了允许AJAX从Amazon S3 GET的? (访问控制 - 允许 - 产地)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储在Amazon S3中JSON对象,我想在Javascript中直接加载数据S3。我的GET看起来pretty的通用的:

I'm storing JSON objects in Amazon S3, and I'd like to load that data directly from S3 from Javascript. My GET looks pretty generic:

$.ajax({
    'type':'GET',
    'url':'http://s3.amazonaws.com/mybucketname/'+id,
    'dataType':'text',
    'success':function(msg) {
        alert(msg);
    }
});

我收到以下错误:

I get the following error:

XMLHttpRequest cannot load http://s3.amazonaws.com/whatever/whatever. Origin http://mylocalhostname:9000 is not allowed by Access-Control-Allow-Origin.

我可以使用curl,或者从我的浏览器导航到那里直接得到S3的URL。难道我真的要通过自己的服务器上有代理所有这些要求?

I can get that URL from S3 using curl, or by navigating there directly from my browser. Am I really going to have to proxy all of these requests through my own servers?

推荐答案

S3现在支持使用CORS文件跨域请求

S3 now supports Cross Domain Requests using CORS file

您可以在这里找到更多的信息

You can find more information here

<一个href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/cors.html#how-do-i-enable-cors">http://docs.amazonwebservices.com/AmazonS3/latest/dev/cors.html#how-do-i-enable-cors

<一个href="http://aws.typepad.com/aws/2012/08/amazon-s3-cross-origin-resource-sharing.html">http://aws.typepad.com/aws/2012/08/amazon-s3-cross-origin-resource-sharing.html

这篇关于允许AJAX从Amazon S3 GET的? (访问控制 - 允许 - 产地)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆