javascript - 如何使用 http api 从 javascript 中删除 AWS S3 中的密钥
问题描述
当我尝试从我的 AWS S3 中删除密钥时,我似乎无法克服该"403 (Forbidden)"
错误或后续错误。<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>...</RequestId><HostId>...</HostId></Error>
为了进行测试,我已经公开了我的存储桶,并为 DELETE 添加了 CORS 规则,并允许对目录中的所有文件使用 s3:DeleteObject,如下所示
"Resource": "arn:aws:s3:::...(directory)/*
:
到目前为止,这是我在代码中尝试过的:
function deleteS3file(bucket, path, filename) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4) {
if (Math.floor(xmlhttp.status/100) != 2){
alert(filename +" not deleted from S3\n"+xmlhttp.status+" "+xmlhttp.responseText);
// http://mysourceip.com/
} else {
console.log(filename +" deleted from S3");
}
}
}
xmlhttp.open("DELETE", bucket, true);
xmlhttp.send(path+'/'+filename);
}
(这只是给了我 403 错误)
和
function deleteS3file(bucket, path, filename) { // path without leading slash
var fd = new FormData();
fd.append('key', path+filename); // full path to file
fd.append('acl', 'bucket-owner-full-control');
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4) {
if (Math.floor(xmlhttp.status/100) != 2){
alert(filename +" not deleted from S3\n"+xmlhttp.status+" "+xmlhttp.responseText);
// http://mysourceip.com/
} else {
console.log(filename +" deleted from S3");
}
}
}
xmlhttp.open("DELETE", bucket, true);
xmlhttp.send(fd);
}
(这给了我 403 和 AWS Access Denied 错误)
我知道我的存储桶配置是正确的,因为我可以毫无问题地上传文件。AWS 文档似乎指向我的第一个解决方案,但我什至没有收到 AWS 回复。
解决方案
推荐阅读
- python - 在 pytorch 中为 CNN 设置自定义内核
- jdbc - Databricks 使用 ActiveDirectoryPassword 连接到 Azure SQL DB 时出错
- javascript - ng-disabled 不禁用 html 元素
- java - EditText 中 DrawableLeft 的 OnClickListener?
- c++ - 使用三重指针将数组作为参数
- wpf - Windows 10 磁力链接上的安全消息
- html - 按钮丢失或在身体之外
- uwp - 如何知道套接字中是否有来自服务器的数据?
- gnupg - Gnupg - 解密文件
- node.js - 在firestore中使用where条件从子集合的所有文档中删除数据