Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Undefined when trying to send data to server nodeJS

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;
};}
  
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When you use mode: 'no-cors' in your request you can't access the API response, you should configure cors in your backend to allow requests from all origins and remove mode: 'no'cors' from your request

https://expressjs.com/en/resources/middleware/cors.html

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!