跨源策略错误
Cross Origin Policy error
我正在从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);
您需要在存储桶上启用它,然后一切都很好。
遵循亚马逊官方指南:
http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 我如何修复包含在captcha的addthis中的错误
- 导致内容安全策略(CSP)冲突错误的本地jquery.js文件
- 使用 sailsjs 护照身份验证本地策略既不会给出任何错误,也不会对用户进行身份验证
- 创建映射时出现同源策略错误
- 跨源策略错误
- REST API错误:拒绝连接到..因为它违反了以下内容安全策略指令:
- Passport.js和MongoStore错误“;在MongoStore中找不到连接策略”;
- Modernizr导致内容安全策略(CSP)违反错误
- 当无法控制同源策略错误时,如何避免同源策略错误
- firefox OS内容安全策略错误,基于XHR的应用程序在Index.html
- 快递和护照错误:未知的认证策略“登录”
- Chrome插件和内容安全策略错误
- 错误:访问受限的URI被拒绝-同源策略
- 内容安全策略:无法't在Firebug中解析无效的源chrome扩展-FB脚本错误
- Tumblr 上的 JS:“跨域资源共享策略”错误