-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
I have this scenario:
- I've created a collection to log some data.
When a user posts to this collection I want to call a custom dpd-event where I will call an external service asynchronously. When the external call ends I want to finish up some details in the post data.
//this is the custom dpd-event
//file resources\cloudinarysrv\post.js
var cloudinary = require('cloudinary');
var done = ctx.done // remember this to end the response (async)
ctx.done = function () { } // dummy function for autoresponse (sync)
cloudinary.config({
cloud_name: 'my_cloud_name',
api_key: 'my_key',
api_secret: 'my_secret'
});
cloudinary.v2.uploader.upload(ctx.body.ficheiro, function (error, result) {
if (error) {
cancel(error.message, 401);
}
else {
console.log("resposta do cloudinary");
console.log(JSON.stringify(result));
setResult(result);
}
});
As to the collection:
//this is the collection
//resources\exchange\validate.js
var self = this;
if (self.logotipo) {
dpd.cloudinarysrv.post({ ficheiro: self.logotipo }, function (result, error) {
if (error) {
self.logotipo = "upload error image default...";
self.secureLogotipo = "upload error secured image default...";
}
else {
console.log(JSON.stringify(result));
console.log("já guardou na cloud e está de volta...");
//this should be get after the external call in dpd-event finishes but the call is not being done asynchronously
self.logotipo = result.url;
self.secureLogotipo = result.secure_url;
}
});
}
else {
self.logotipo = "imagem default...";
self.secureLogotipo = "imagem default segura...";
}
I'm not grasping the async calls concept... can someone help?
Metadata
Metadata
Assignees
Labels
No labels