gpt4 book ai didi

javascript - Angular/JS 将图像上传到 AWS 预签名 URL

转载 作者:行者123 更新时间:2023-11-28 05:28:14 25 4
gpt4 key购买 nike

每次我尝试将图像上传到预签名网址时。我收到预检警告,但上传失败。

我需要做什么?

enter image description here

据我所知,我应该上传到图像中 url 属性中可以看到的 url。

我尝试了各种变体,但这是我当前的上传代码:

$.ajax({
type: 'PUT',
url: pData.url,
// Content type must much with the parameter you signed your URL with
contentType: 'binary/octet-stream',
// this flag is important, if not set, it will try to send data as a form
processData: false,
// the actual file is sent raw
data: $scope.file
})
.success(function() {
alert('File uploaded');
})
.error(function() {
alert('File NOT uploaded');
console.log( arguments);
});

我该如何解决这个问题,我无法访问为我提供签名网址的后端,是否可能是负责人或亚马逊的 CORS 错误,我该如何检查?

感谢您的建议。

最佳答案

这是 CORS 问题。您需要要求管理员将其放入 S3 存储桶的 CORS 配置中。

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

关于javascript - Angular/JS 将图像上传到 AWS 预签名 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39945763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com