首页 > 解决方案 > 将 s3 存储桶图像 url 转换为 base64 时出错

问题描述

有人可以帮我获取上传到 AWS s3 存储桶的图片 URL 的 base64。即使在 S3 CORS 配置上设置了多个设置后,我每次都会收到 CORS 错误。下面是我的代码和 CORS 设置。

let xhr = new XMLHttpRequest();
xhr.onload = function () {
  var reader = new FileReader();
  reader.onloadend = function () {
    callback(reader.result);
  }
  reader.readAsDataURL(xhr.response);
};

xhr.onerror = function() {

}
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();


<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>

标签: javascriptamazon-s3

解决方案


推荐阅读