From b448ab27e8c92e4efe917c61ac9b42139b94da03 Mon Sep 17 00:00:00 2001 From: dblythy Date: Mon, 16 Nov 2020 19:03:52 +1100 Subject: [PATCH 1/3] Documentation for deleting files Closes #726 --- _includes/js/files.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/_includes/js/files.md b/_includes/js/files.md index 46e3f3be8..ff35d55f9 100644 --- a/_includes/js/files.md +++ b/_includes/js/files.md @@ -111,9 +111,22 @@ Parse.Cloud.httpRequest({ url: profilePhoto.url() }).then(function(response) { }); ``` + ## Deleting Files -You can delete files that are referenced by objects using the [REST API]({{ site.baseUrl }}/rest/guide/#deleting-files). You will need to provide the master key in order to be allowed to delete a file. +Starting with Parse Server 4.2.0, you can delete files using cloud code. + +```javascript +Parse.Cloud.beforeDelete('Profile', async (req) => { + const profile = req.object; + const profilePhoto = profile.get("photoFile"); + await profilePhoto.destroy({ useMasterKey: true }) +}); +``` + +A master key is required in order to delete files. + +Alternatively, you can delete files that are referenced by objects using the [REST API]({{ site.baseUrl }}/rest/guide/#deleting-files). If your files are not referenced by any object in your app, it is not possible to delete them through the REST API. From 1b54ccafbc1379115baa5e8e045e0e3e9f722ff0 Mon Sep 17 00:00:00 2001 From: dblythy Date: Tue, 17 Nov 2020 22:26:36 +1100 Subject: [PATCH 2/3] Update files.md --- _includes/js/files.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/_includes/js/files.md b/_includes/js/files.md index ff35d55f9..081305e6e 100644 --- a/_includes/js/files.md +++ b/_includes/js/files.md @@ -114,7 +114,11 @@ Parse.Cloud.httpRequest({ url: profilePhoto.url() }).then(function(response) { ## Deleting Files -Starting with Parse Server 4.2.0, you can delete files using cloud code. +You can delete files that are referenced by objects using the [REST API]({{ site.baseUrl }}/rest/guide/#deleting-files). You will need to provide the master key in order to be allowed to delete a file. + +If your files are not referenced by any object in your app, it is not possible to delete them through the REST API. + +Alternatively, starting with Parse Server 4.2.0, you can delete files using cloud code. ```javascript Parse.Cloud.beforeDelete('Profile', async (req) => { @@ -124,12 +128,6 @@ Parse.Cloud.beforeDelete('Profile', async (req) => { }); ``` -A master key is required in order to delete files. - -Alternatively, you can delete files that are referenced by objects using the [REST API]({{ site.baseUrl }}/rest/guide/#deleting-files). - -If your files are not referenced by any object in your app, it is not possible to delete them through the REST API. - ## Adding Metadata and Tags Adding Metadata and Tags to your files allows you to add additional bits of data to the files that are stored within your storage solution (i.e AWS S3). From 88e952ae7be868f177844c37673dd8eb1d9e1d93 Mon Sep 17 00:00:00 2001 From: dblythy Date: Tue, 17 Nov 2020 23:53:53 +1100 Subject: [PATCH 3/3] Update files.md --- _includes/js/files.md | 1 - 1 file changed, 1 deletion(-) diff --git a/_includes/js/files.md b/_includes/js/files.md index 081305e6e..2f04665e5 100644 --- a/_includes/js/files.md +++ b/_includes/js/files.md @@ -111,7 +111,6 @@ Parse.Cloud.httpRequest({ url: profilePhoto.url() }).then(function(response) { }); ``` - ## Deleting Files You can delete files that are referenced by objects using the [REST API]({{ site.baseUrl }}/rest/guide/#deleting-files). You will need to provide the master key in order to be allowed to delete a file.