Start a new topic

File(s) will not be deleted

Hello 


I'm trying since hours to delete file(s) in backend by Business Logic but file(s) won't be deleted. I assume what I have done is pretty ok. There must be a small change then it works: 

var appKey = modules.backendContext.getAppKey();
var masterSecret = modules.backendContext.getMasterSecret();
var authString = "Basic " + modules.utils.base64.encode(appKey + ":" + masterSecret);

modules.request.get(        // with post: res.status = 201
      {uri: 'https://baas.kinvey.com/appdata/kid_xxxxxxx/_blob/',
       method: 'DELETE',
        params: {'gameid':gameId},
       headers: {"Authorization":authString}
      },
            function(error, res, body){
            if (error){
              logger.info(error);
            } else {
              logger.info ("del ok");
              response.body = JSON.parse(body);
              logger.info(res.status);
              logger.info (JSON.stringify(response.body) );
            }
});

 The execution heads into the else case (no error) and outputs this:

  • del ok
  • 200
  • [{"_id":"9b42b619-0a0f-1c6b-9d6d-8701c5fda37e","gameid":"GNREB1A","_filename":"9b42b...


That tells me everything is ok but the file(s) with gameid = GNREB1A won't be deleted!


Someone an idea why files still there?


Desperate greetings






Hello Tyger,


Please use "Modules.request.request" instead of "Modules.request.get" and your file will be deleted. For more info, please check this link. Also, the URL I used is "https://baas.kinvey.com/blob/kid_xxxxxx/", not "https://baas.kinvey.com/appdata/kid_xxxxxxx/_blob/" as mentioned on this link.  Following is my code snippet:


modules.request.request(       
      {uri: 'https://baas.kinvey.com/blob/kid_xxxxxx/dc7eea0f-3b18-4ff7-b76f-9d482f72xxxx',
       method: 'DELETE',
       "headers" : {
          "Authorization": request.headers.authorization
        }
      },
            function(error, res, body){
            if (error){
              logger.info ("entered error");
              logger.info(error);
              response.error(error);
              
            } else {
              logger.info ("deleted");
              response.body = JSON.parse(body);
              logger.info(res.status);
              logger.info (JSON.stringify(response.body) );
              response.complete();
            }
});


You can use the collection access module of BL for accessing "_blob" collection.


Hope this helps!



Thanks,

Pranav

Kinvey


Thanks a ton, Pranav, for your help! Sadly I was not able to make your version work:  

var logger = modules.logger;
modules.request.request(
    {uri: 'https://baas.kinvey.com/blob/kid_xxxxxxxx?query={"gameid":"'+gameId+'"}',
     method:'DELETE',
     headers: {
          "Authorization": request.headers.authorization
        }
     //params: {'gameid':gameId}, // won't work either this way
    },
    function(error, res, body){
      if (error){
              logger.info ("entered error");
              logger.info(error);
              response.error(error);
            } else {
              response.body = JSON.parse(body);
              logger.info(res.status);
              logger.info (JSON.stringify(response.body) );
              response.complete();
            }
    });

    

Output:

400

{"error":"The request was not understood.","request":"DELETE /blob/kid_xxxxxxxx?query={%22gameid%22:%22GNJB5B4%22}"}... 


I found out that the URI path is causing the error. So I switched back to mine:

uri: 'https://baas.kinvey.com/appdata/kid_SkYzM4SHM/_blob/?query=...


Your URI looks much cleaner but can't makie it work with it. :(


In between I was able to make it work with the "del" command as well:


No big thing but I wasn't able to hand over the query parameter by "params":

params: {'gameid':gameId}


{"error":"MissingRequestParameter","description":"A required parameter is missing from the request.","debug":"The request URI should either specify th...


400


Probably my fault somewhere in the code. Nevertheless it works like a charm attaching it to the URI path.


The fully working example:

 

// works also with modules.request.del(...)
    modules.request.request(
    {uri: 'https://baas.kinvey.com/appdata/<kid_xxxxxxxx>/_blob?query={"gameid":"'+gameId+'"}',
     method:'DELETE',
     headers: {
          "Authorization": request.headers.authorization
        }
     //params: {'gameid':gameId},
    },
    function(error, res, body){
      if (error){
              logger.info ("entered error");
              logger.info(error);
              response.error(error);
            } else {
              response.body = JSON.parse(body);
              logger.info(res.status);
              logger.info (JSON.stringify(response.body) );
              response.complete();
            }
    });

 

Thanks and Regards


Login or Signup to post a comment