2

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.

justadeveloper
  • 86
  • 4
  • 12

1 Answers1

4

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.

Community
  • 1
  • 1
  • Correct! Keep in mind though that DELETE request requires a secret key. The web page where you are putting this code needs to be protected, otherwise anyone can take the secret key and send DELETE requests to your Uploadcare account. – David Avsajanishvili Dec 12 '14 at 10:26
  • 1
    Right now this will not work, as Uploadcare API does not allow cross origin requests. We're working on this though/ – Dmitry Mukhin Dec 12 '14 at 11:40
  • As mojo stated that this will not work, other way/workaround to call delete request? – justadeveloper Dec 12 '14 at 23:33
  • Uploadcare API allows cross origin requests since 2014-12-24, so if you're up to exposing your key or want to add roundtrip to your backend to get proper Authentication header value, go for it. – Dmitry Mukhin Jan 21 '15 at 12:25