Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda