My uploadPhoto function should return the id (int) of the photo that has been uploaded.
so inside my main function I've got let photoId = await uploadPhoto(image, name);
here's the code of the uploadPhoto function: First attempt
async function uploadPhoto(image, name) {
try {
let file = fs.readFileSync( image );
await client.uploadFile({
name: image,
type: "image/jpg",
bits: file
}, function( error, data ) {
return data.id
});
} catch (err) {
console.log(err);
}
}
Second attempt
async function uploadPhoto(image, name) {
try {
let file = fs.readFileSync( image );
function uploadF (callback){
client.uploadFile( { name: image, type: "image/jpg", bits: file } , function( error, data ) {
return callback(data.attachment_id);
});
}
let res = await uploadF(function (data){
return data;
});
} catch (err) {
console.log(err);
}
}