Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda