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?

+3


source to share


3 answers


There is a REST API for this, see here



+1


source


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);

      

+1


source







All Articles