I have a collection that has references to images, and when the user updates that collection with new images, I want to delete the old images. I am keeping references to the URL for the old images to pass into a function that is written in the cloud code.
I am running all of this local on my computer, however I get the same issue when I run this with the server running on Heroku. This is being called from the iOS SDK.
Here is the function in question:
Parse.Cloud.define('removeOldFilesFromDB', function (request, response) {
var fileUrls = request.params.fileUrls;
var promises = [];
for (var a = 0; a < fileUrls.length; a++) {
promises.push(Parse.Cloud.httpRequest({
method: 'DELETE',
url: fileUrls[a],
headers: {
'X-Parse-Application-Id': process.env.APP_ID || 'myAppId',
'X-Parse-Master-Key': process.env.MASTER_KEY || 'myMasterKey'
}
}));
}
Parse.Promise.when(promises).then( function (result) {
console.log("Successfully deleted files");
response.success(result);
}, function(a,b,c,d,e) {
console.log("Nope jacked it up!");
response.error("Error deleting files");
});
})
When I call the code in question, I don't even see the DELETE request in the parse-server logs at all.
I have the verbose: true
flag set in my config, and this is the verbose output to the logs that I get when making this call from the client:
verbose: POST /parse/functions/removeOldFilesFromDB { host: 'e0ae0682.ngrok.io',
'x-parse-client-version': 'i1.12.0',
accept: '*/*',
'x-parse-session-token': 'r:5290c76c47678213770765d990ee38b6',
'x-parse-application-id': 'myAppId',
'x-parse-client-key': 'myClientKey',
'x-parse-installation-id': '3fafc219-1c63-4d68-b42f-5caa3e1c27cb',
'accept-language': 'en-us',
'accept-encoding': 'gzip, deflate',
'x-parse-os-version': '8.1 (12B411)',
'content-type': 'application/json; charset=utf-8',
'content-length': '204',
'user-agent': 'Spin%20the%20Bottle/1 CFNetwork/711.1.12 Darwin/14.0.0',
'x-parse-app-build-version': '1',
'x-parse-app-display-version': '1.0',
'x-forwarded-for': '71.163.238.223' } {
"fileUrls": [
"http://e0ae0682.ngrok.io/parse/files/myAppId/7b5b50e2871af27971be0425f367ab96_file.bin",
"http://e0ae0682.ngrok.io/parse/files/myAppId/cff909602b60b15331b1ac60a4f08697_file.bin"
]
}
Nope jacked it up!
verbose: error: code=141, message=Error deleting files
So it's odd that the DELETE call is not even showing up in there. Am I calling it wrong with the Parse.Cloud.httpRequest method or something?
If I hit the values for fileUrl in my browser, it downloads the images I'm trying to delete so the path is correct.
This is on the latest released version of parse-server, 2.2.10.
These were the instructions that I was following thinking that this is the correct way to do this:
https://parse.com/docs/rest/guide/#files-deleting-files
And this here to make the rest call from the cloud code:
https://parse.com/questions/making-a-rest-call-from-within-cloud-code
According to that, it says I can use Parse.Cloud.httpRequest to make REST calls, so I am not sure what you are referring to as that not the correct ways. Both of those have links to the docs and that is what I followed.
So I am obviously doing something wrong but I am not sure, anyone able to help out?
Just remove myAppId from file URL.
(eg)
from
http://e0ae0682.ngrok.io/parse/files /myAppId /7b5b50e2871af27971be0425f367ab96_file.bin
to
http://e0ae0682.ngrok.io/parse/files/7b5b50e2871af27971be0425f367ab96_file.bin
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.