删除Parse文件

时间:2014-09-09 13:29:21

标签: javascript parse-platform

如果我有一个带有文件属性的Parse对象,那么我会删除原始对象。

  1. 是否删除了孤立文件?
  2. 如果没有,我该如何删除文件?
  3. 我正在使用Javascript尝试放置"删除"之后在云代码中执行所有操作一起运作并级联删除。

    修改

    好的,稍后快速测试一下。文件不会被删除。他们是孤儿。那么,如何在云代码中删除文件?

3 个答案:

答案 0 :(得分:1)

有一个REST API,请参阅here

答案 1 :(得分:1)

答案 2 :(得分:1)

其他答案已经指出正确的链接......以下显示我是如何在浏览器中完成的...

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