when i try send a image to API Rest from android the image ( in base64 ) arrived but npm response that => (node:16247) UnhandledPromiseRejectionWarning: Error: Invalid base64 string,
but when i put the base string in a converter this work.
this is the code of api
API:
router.post('/CreateAccount/Mobile', async (req, res)=>{ let Image = await Base64ToImage({ target: "", Base64:
req.body.imageBase64, Base64Ext: req.body.imageExtencion })
return await res.json(Image)
})`
this function go to this function:
`async function Base64ToImage(data){
if(data.Base64Ext){
var Extencion = data.Base64Ext
}else{
var Extencion = “jpg”
}
const pathNow = require(‘path’);
let Base64 = data.Base64
var path = pathNow.join(__dirname + /../../uploads/${data.target}
);
var optionalObj = { ‘fileName’: ${UUID()}.${Extencion}
};
// Imagen es subida
let response = await base64ToImage(Base64, path, optionalObj);
if(response.fileName) return response.fileName
}`