I'm trying to send data to my server so that I can work with external API. I'm learning now slowly so please forgive for my noobness :) In the code below I converted the elements of an array into a base64 strings (solution). These strings are the ones I would like to send to the server with fetch, however the node server returned UNDEFINED. I suppose I'm wrong in some kind of process (read about async/await etc)... Could someone help me out? Thanks a lot.
NODEJS:
app.post("/upload",upload.any(),(req,res)=>{
console.log(req.files)
res.setHeader("Access-Control-Allow-Origin","*")
res.end("Done.")
});
CLIENT SIDE:
function getBase64(item,index,arr) {
let reader = new FileReader();
reader.readAsDataURL(item);
reader.onload = function(e) {
var rawLog = reader.result; // DataURL - rawLog
var solution = rawLog.split("base64,")[1]; //Rimozione parte prima di base64
// console.log(solution);
// console.log(rawLog);
fetch("http://localhost:3000/upload",{
method:'post',
mode: 'no-cors',
body:solution
}).catch(console.error);
return reader.result;
};}