Fogmeister
Fogmeister

Reputation: 77641

Deleting Parse files

If I have a Parse object with a file attribute on it and then I delete the original object.

  1. Does it delete the orphaned file?
  2. If not, how do I delete the file?

I'm doing everything in cloud code using Javascript trying to put an "After delete" function together and cascading the delete down.

EDIT

OK, a quick test later. The files are not deleted. They are orphaned. So, how to delete the file in cloud code?

Upvotes: 3

Views: 1759

Answers (3)

zCoder
zCoder

Reputation: 101

Other answers already pointed out the proper links... The following shows how I did it from within 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);

Upvotes: 1

Donal
Donal

Reputation: 32713

There is a REST API for that, see here

Upvotes: 1

Related Questions