How to delete file/s through rest api in uploadcar

2019-07-11 19:40发布

I'm trying to delete file/s in uploadcare rest api using jquery ajax. Here is my current codes for jquery:

$.ajax({
            url: "http://api.uploadcare.com/files/" + $("#photoguid").val() + "/",
            type: "DELETE",
            contentType: "application/json"
});

My question is how to implement it properly because every time I call this, it redirects me to login page, that's what I see when checking in fiddler and I'm not sure where to put the authorization. I'm only using free trial for this.

1条回答
Juvenile、少年°
2楼-- · 2019-07-11 20:17

The docs do say Rest calls must be done via https. https://uploadcare.com/documentation/rest/

As for the request headers looks like that was answered here: How can I add a custom HTTP header to ajax request with js or jQuery?

Here is an example for your case:

$.ajax({
    url: "https://api.uploadcare.com/files/" + $("#photoguid").val() + "/",
    type: "DELETE",
    headers: { "Authorization": "Uploadcare.Simple demopublickey:demoprivatekey" }
});

Since 2014-12-24, Uploadcare API allows cross origin requests so if you're up to exposing your private key or want to add roundtrip to your backend to get proper Authentication header value, go for it.

查看更多
登录 后发表回答