跨源策略错误

时间:2015-01-05 09:25:50

标签: javascript angularjs amazon-s3

我正在阅读S3的图像,我正在使用angularjs,当我打开页面时,我收到错误

Image from origin 'https://feazt-static.s3.amazonaws.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8000' is therefore not allowed access. 

当我再次重新加载页面时,图像正在正确加载。请帮助我。

我实施的代码:

$timeout(function() {
        var canvas = document.createElement("canvas");
        var context = canvas.getContext("2d");
        var img_obj = document.getElementById("img_file_"+index);
        img_obj.addEventListener('load', function() {
            canvas.width = this.width*2;
            canvas.height = this.height*2;
            context.drawImage(this, 0, 0, canvas.width, canvas.height);
            this.setAttribute("src",canvas.toDataURL()); 
        });
        img_obj.setAttribute('crossOrigin', 'anonymous');
        img_obj.setAttribute("src",arg);
    }, 2000);

1 个答案:

答案 0 :(得分:1)

你需要在你的水桶上启用它,然后你们都很好。

按照亚马逊官方指南:

http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html