我正在尝试使用上载的REST API删除图像,我的工作与文档完全一样,这篇文章说,但仍然无法删除图像,这是我的代码:
html:
<html>
<script charset="utf-8" src="https://ucarecdn.com/libs/widget/3.2.2/uploadcare.full.min.js"></script>
<body>
<div class="main">
</div>
<div>
<button class="uploader">Upload an image</button>
<input class="deletet" />
<button class="getit">delete something</button>
</div>
</body>
<footer>Developep by Francisco Jimenez</footer>
</html>
JavaScript:
function deleteb(uuid){
$.ajax({`
url: "https://api.uploadcare.com/files/"+uuid+"/",`
type: "DELETE",
headers: { "Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Accept": "application/vnd.uploadcare-v0.5+json",
"Access-Control-Allow-Methods": "HEAD, GET, OPTIONS",
"Authorization": "Uploadcare.Simple publickey:privatekey"
},
success: function(result){
alert("yessss");
console.log(result);
},
error: function (result){
alert("ouuuh");
console.log(result);
}
});
}
我不断得到的响应是:Cross-Origin Request Blocked
:相同的原点策略在https://api.uploadcare.com/files/files/c2e166b5-17b9-493f-bf8c-bf8c-bf8c-b33da27842ca至1/上删除阅读远程资源。(原因:CORS标题"访问控制">
我做错了什么?
您将响应CORS标题设置为请求。这没有任何意义,但更重要的是,由于未识别的标题,服务器拒绝您的请求。例如,我在您的代码中得到以下错误:
请求标头访问访问控制 - 允许原素不会由访问前响应中的访问权限控制者允许。
以下代码非常适合我:
$.ajax({
url: "https://api.uploadcare.com/files/8b147fe2-b677-407b-8c28-3d596187ac93/",
type: "DELETE",
headers: {
"Accept": "application/vnd.uploadcare-v0.5+json",
"Authorization": "Uploadcare.Simple demopublickey:demoprivatekey"
},
success: function(result){
alert("yessss");
console.log(result);
},
error: function (result){
alert("ouuuh");
console.log(result);
}
});