Я не знаю, как вернуть значение значений переменной, найденных в первой функции, а затем использовать их, как показано ниже, с then ().
async escribeSolido(contenido: any) {
const ancho = 300;
...
contenido.map(async (item: any) => {
let image = new Jimp(ancho, alto, item.color, (err: any, imagen: any) => {
if (err) {
throw err;
}
});
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK)
.then(font => {
...
return image;
})
.then(async(image) => {
let file = uuid()+'.png';
const path = __dirname +'/public/'+file;
values = await cloudinary.v2.uploader.upload(path, {folder: 'anuncios_basicos'});
/*Return this values*/
console.log('Values -----: ', values);
})
})
});
//return values;
}
Моя другая функция
await abService.escribeSolido(contenido)
.then((value: any) => console.log('Values: ', value)) // undefined
.catch((err: any) => console.log(err))
Мои результаты
Values: undefined
POST /api/anuncio 200 75.451 ms - 463
Values -----: { public_id: 'anuncios_basicos/qnp6s1ptxwzxc0rrwzhp',
....
url:
'http://res.cloudinary.com/dshskwox0/image/upload/v1554922819/anuncios_basicos/qnp6s1ptxwzxc0rrwzhp.png',
secure_url:
'https://res.cloudinary.com/dshskwox0/image/upload/v1554922819/anuncios_basicos/qnp6s1ptxwzxc0rrwzhp.png',
original_filename: 'e59df336-eba1-4b17-9101-fe6bfeed07dc' }