Removing Parse Files
If I have a Parse object with a file attribute on it, then I delete the original object.
- Does it delete the lost file?
- If not, how do I delete the file?
I am doing everything in cloud code using Javascript trying to combine the "After Delete" function and cascade the delete.
EDIT
OK, a quick test later. Files are not deleted. They are orphaned. So how to delete a file in cloud code?
Another option is to click on the clear button located on your app's settings page (I saw someone else mention deleting using the REST API ).
You can delete files referenced by objects using the REST API. You will need to provide a master key to allow the file to be deleted.
If your files do not reference any object in your application, they cannot be deleted using the REST API. You can request to clean up unused files on the application settings page. Be aware that this could break functionality that depended on accessing unreferenced files via their URL property. Files that are currently associated with the object will not be affected.
There is a REST API for this, see here
Other answers have already pointed to the correct links ... Below is how I did it from the browser ...
// 1. in a browser console, go to their domain do avoid cross-domain failure later
// (paste this by itself)
document.location.href='https://api.parse.com';
// 2. load up jquery
// (paste this and the rest of the script into the console only after the page url above loads)
(function(){
var newscript = document.createElement('script');
newscript.type = 'text/javascript';
newscript.async = true;
newscript.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript);
})();
// the goods
function deleteParseFile(appId, masterKey, filename)
{
var serverUrl = 'https://api.parse.com/1/files/' + filename;
$.ajax({
type: "DELETE",
beforeSend: function(request) {
request.setRequestHeader("X-Parse-Application-Id", appId);
request.setRequestHeader("X-Parse-Master-Key", masterKey);
},
url: serverUrl,
success: function(results) {
console.log('success:', results)
}, error: function(error) {
console.log('error:', error);
}
});
}
// 3. set the file you want deleted... and delete it
var appId = "<YOUR_APPLICATION_ID>";
var masterKey = "<YOUR_MASTER_KEY>";
// this filename can be found in the file object or the parse image URL
var filename = "tfss-abcd1234-dcba-4321-1a2b-112233aabbcc-my-file.gif";
deleteParseFile(appId, masterKey, filename);