[英]AWS S3 PUT request with presigned URL not working in javascript
我正在使用 lambda 生成预先签名的签名以将文件上传到 S3 存储桶。 当我将 lambda 与 Postman/CURL 一起使用时,它返回的签名有效。 但是,当我尝试从我的程序发出 PUT 请求时,它会将 localhost 附加到预先签名的 URL。 我在本地计算机上使用 IIS 作为 Web 服务器。 可能与 IIS 配置有关吗? 或者我在代码或应用程序配置本身中做错了什么?
我的代码如下:
const xhr = new XMLHttpRequest();
xhr.open('PUT', preSignedURL);
xhr.onreadystatechange = () => {
if(xhr.readyState === 4){
if(xhr.status === 200){
alert('File Ready to n upload. xhr.status: ' + xhr.status + 'xhrstatustext:' +xhr.statusText);
}
else{
alert('Could not upload file.');
}
}
};
xhr.send(file);
这是我自己想出来的。 lambda 函数返回的 URL 格式不正确。 我所要做的就是删除第一个和最后一个引号,然后将我的文件上传到 S3。
var preSignedURL = preSignedURL.substring(1, preSignedURL.length-1);
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.