If I want to delete file, I need to make a DELETE request to parse server. But this is extra work. Why cant we delete file like we delete parse objects.
Something like this would be great: await parseFile.delete({useMasterKey:true});
This would be much easier. Can you tell me why this is not the way to go. What are the vulnerabilities?
Thats great I looked in JS docs but didnt see that. Thank you. Docs needs to be updated or maybe they intensionally didnt add because its node specific? Anyway thank you again.
It’s a good suggestion. There a number of documentation issues which are up for grabs, this subject being one of them. Naturally as Parse Server continues to evolve, updating documentation requires a lot of time, time that often is spent on building new features .
I’ve submitted a PR that will update the docs to include information around deleting files via JS.
Assuming that I have array of [Parse.File] in the database object… I can’t find any Parse.File.destroyAll(files, {useMasterKey: true}); as there is for Parse.Object in the documentations so I have to loop one by one. Am I correct?
Parse.Cloud.afterDelete("Msg", async ({object, log}) => {
//delete files referred by the message
const files = object.get("fls");
try {
for (let i = 0; i < files.length; ++i) {
const file = files[i];
await file.destroy({ useMasterKey: true });
}
//Parse.File.destroyAll(files, {useMasterKey: true});
} catch (e) {
log.error(`Error removing file objects: ${error.code}: ${error.message} referred in message ${object.id}`);
}
return;
});