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}
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
Tayger
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:
The execution heads into the else case (no error) and outputs this:
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