Skip to content

Commit b448ab2

Browse files
authored
Documentation for deleting files
Closes parse-community#726
1 parent b36fc11 commit b448ab2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

_includes/js/files.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,22 @@ Parse.Cloud.httpRequest({ url: profilePhoto.url() }).then(function(response) {
111111
});
112112
```
113113

114+
114115
## Deleting Files
115116

116-
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.
117+
Starting with Parse Server 4.2.0, you can delete files using cloud code.
118+
119+
```javascript
120+
Parse.Cloud.beforeDelete('Profile', async (req) => {
121+
const profile = req.object;
122+
const profilePhoto = profile.get("photoFile");
123+
await profilePhoto.destroy({ useMasterKey: true })
124+
});
125+
```
126+
127+
A master key is required in order to delete files.
128+
129+
Alternatively, you can delete files that are referenced by objects using the [REST API]({{ site.baseUrl }}/rest/guide/#deleting-files).
117130

118131
If your files are not referenced by any object in your app, it is not possible to delete them through the REST API.
119132

0 commit comments

Comments
 (0)