您当前的位置: 首页 >  阿里云

彭世瑜

暂无认证

  • 4浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

阿里云OSS图片访问出现跨域:Access to image at from origin has been blocked by CORS policy

彭世瑜 发布时间:2022-09-08 15:08:06 ,浏览量:4

问题描述




// 使用js Image 对象报错
let image = new Image()
image.setAttribute('crossOrigin', 'Anonymous')
image.src = url

报错

Access to image at xxx
from origin xxx
has been blocked by CORS policy: 
No 'Access-Control-Allow-Origin' header is present on the requested resource.
解决:

阿里云OSS:权限控制/跨域访问中 设置跨域规则:

来源: *
允许 Methods: GET POST PUT DELETE HEAD
允许 Headers:*
暴露 Headers:ETag、 x-oss-request-id、x-oss-version-id
缓存时间(秒):0

1、方式一:

浏览器设置:停用缓存

在这里插入图片描述 2、方式二:

添加元数据

// 简单上传
result = await client.put(filename, file, {
   meta: {
     'Cache-Control': 'no-cache',
   },
 })

参考 解决阿里云oss 图片跨域问题 管理文件元信息

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0739s