no response from destroy method
I am trying to delete the images from the client-side but destroy method not working, does not delete the images and at the same not giving me any error.
I am working with react.js and this is my method:
deleteProductHandler = id => {
db.collection("products")
.doc(id)
.delete()
.then(() => {
// update the UI
const products = [...this.state.products];
let images = [];
products.forEach((product, index) => {
if (product.id === id) {
products.splice(index, 1);
images = [...product.images];
this.setState({ show: false, products: products });
}
});
// delete images from cloudinary
let links = images
.map(link => {
return link.match("products/");
})
.map(link => {
const newlink = link.input.slice(link.index);
const newlink2 = newlink.slice(0, -4);
return { publicId: newlink2 };
});
let publicIds = [];
for (let key in links) {
publicIds.push(links[key].publicId);
}
console.log(publicIds);
// i got all publicIds here without any problem.
// so dont wory about the code above.
publicIds.forEach(publicId => {
console.log(publicId);
window.cloudinary.v2.uploader().destroy(publicId, (err, res) => {
console.log(err, res);
});
});
})
.catch(err => {
this.setState({ error: err });
});
};
-
Hi,
Can you please share the public_id of the resource/s that you are trying to delete and I will be able to check the logs further?
Best,
Aditi
0 -
Hi there,
Here are the publicIds: products/nvqxgq8brww9yyhhxjdk, products/q8prqylgrrmaw0jy63im
0 -
Hi,
We weren't able to find any destroy() API call logs for your account for either of the specified public_id values - are you sure that the HTTP requests are being made to api.cloudinary.com from your code?
Also, can you confirm which version of our Node.JS SDK you're using, and how the SDK is configured in your application? Are you certainly adding `var cloudinary = require('cloudinary')` at the top? If not, I'd expect to see some console errors from your server, but it's worth verifying that the SDK is installed and configured correctlyThanks,
Stephen
1 -
Hi Stephen,
I realized that no request is made at all, and the reason was that I was trying to use destroy method directly on the client-side(React.js) code which isn't possible.
I am not using node.js or any other server-side languages in my project what can I do to deleting the images?
0 -
It's not possible to delete images from the client-side directly because there's no way to authenticate such a request using details stored in the client - if you had your account's API secret available to the client, any of your users could use that secret to make arbitrary API calls to your account.
The usual method of performing destructing actions from a client-side app is that you also have a server-side component and your app makes a request to your server, which then makes a call to our API after checking the request came from an authorized user and they're allowed to make such a request (e.g. they have admin permission, or they 'own' the asset).
You may need a server-side component for other reasons too, such as handling user logins, storing details about the files a user uploads, etc, so that's a logical place to add a controller to handle deletion or other similar actions
Thanks,
Stephen
0 -
I'm working with Firebase, that why I don't have any server-side component.
anyway, thanks for the explanation, Stephan.
0
Post is closed for comments.
Comments
6 comments