Search code examples
javascriptparse-platform

Delete parse file through cloud code


I have a image as a column in a class. I need to delete that image for a particular row by querying that row. But after querying how to delete that image

I can get the image url by :

var image = results[i].get("imageFile").url();

Can we delete the image by getting the url or is there any other way?


Solution

  • Deleting files is only supported via the REST API at this time. You can try using Parse.Cloud.httpRequest to issue the delete file command.

    You can try to do something like this :

    var image = result.get("imageFile").url();    
    Parse.Cloud.httpRequest({
            method: 'DELETE',
            url: image.substring(image.lastIndexOf("/")+1),
            headers: {
                "X-Parse-Application-Id": "YOUR_APP_ID
                "X-Parse-REST-API-Key" : YOUR_API_KEY"
            }
        );
    

    But do not forget to get yourURL = just the name of your file.

    That's why you need to do

    image.substring(image.lastIndexOf("/")+1),
    

    Exemple yourURL should NOT be http://files.parsetfss.com/19728287-9868-4728-8e49-31472daf0211/tfss-65ff02e3-3d11-45a8-ba25-4955f6c7f677-143569529.jpg

    but tfss-65ff02e3-3d10-45a8-ba25-4955f6c7f677-1435695290.jpg