javascript - 将 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>
解决方案
推荐阅读
- reporting-services - 在 SSRS 报告的 tablix 中的单独列中获取每条记录的总数
- visual-studio-code - 如何知道 VS 代码中使用了哪个 runner?(WSL 上的 VS 代码)
- java - 如何将 HttpGet 更改为 HttpPost?
- php - 问题正确语法mysql php post请求
- sorting - 为什么 Unix 中的 join 命令说我的文件没有排序?
- swift - 系统警报打开时如何防止推送
- python - 基于来自另一个数据框 pandas 的匹配值的新列
- php - 如何在 PHP 中连接到 MySQL 数据库
- php - 使用 while 创建多维数组
- uri - 如何根据 URI 在 sparql 端点中检索结果