通过API删除Uploadcare [英] Uploadcare Delete via API Issue

查看:90
本文介绍了通过API删除Uploadcare的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Uploadcare的REST API删除图像,我的工作与文档和本

I'm trying to delete an image with the REST API of Uploadcare, I'm doing exactly like the documentation and this post says, but still can't manage to delete an image, here is my code:

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:同源策略禁止读取

The response that i keep getting is: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.uploadcare.com/files/c2e166b5-17b9-493f-bf8c-b33da27842ca~1/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

我做错了什么?

推荐答案

您正在为请求设置响应CORS标头.这没有任何意义,但更重要的是服务器由于无法识别的标头而拒绝了您的请求.例如,您的代码出现以下错误:

You are setting response CORS headers to the request. This doesn't make sense but more important is that server rejects your requests due to unrecognized headers. For example I get the following error with your code:

在飞行前响应中,Access-Control-Allow-Headers不允许访问请求标头字段Access-Control-Allow-Origin.

Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

以下代码最适合我:

$.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);
  }
});

这篇关于通过API删除Uploadcare的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆