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
Error al usar captcha y archivo de audio en una página html

Estoy tratando de usar un captcha y enviar un archivo de audio en la misma página. Pero no puedo obtener el nombre del archivo para enviar a la base de datos. TypeError: no se puede desestructurar la propiedad 'nombre de archivo' de 'req.file' porque no está definida.

Intento poner solo una función para enviar la información, pero luego el capctha no funciona.

 form.onsubmit = async e =>{ e.preventDefault() form = e.target var data2 = new FormData(form); var request = new XMLHttpRequest(); data2.append('file',this.ablob); request.open('post','/posts'); request.send(data2); } document.getElementById('form').addEventListener('submit', e => { e.preventDefault(); const captcha = document.querySelector('#g-recaptcha-response').value; return fetch('/posts', { method: 'POST', headers: {'Content-type': 'application/json'}, body: JSON.stringify({captcha}), }) .then(res => res.json()) .then(data => { console.log(data); alert(data.msg); if (data.success) return location.reload(); }); });

El código de fondo:

 routes.post("/posts", multer(multerConfig).single('file') , async(req, res) => { if (!req.body.captcha) return res.json({ success: false, msg: 'Please select captcha' }); // Secret key const secretKey = '6Le1BJ4fAAAAADxI5gIDcnZcMEk5YpXNslAdos4g'; // Verify URL const query = stringify({ secret: secretKey, response: req.body.captcha, remoteip: req.connection.remoteAddress }); const verifyURL = `https://google.com/recaptcha/api/siteverify?${query}`; // Make a request to verifyURL const body = await fetch(verifyURL).then(res => res.json()); // If not successful if (body.success !== undefined && !body.success) return res.json({ success: false, msg: 'Failed captcha verification' }); // If successful const {filename:name, size, key, location: url = '' } = req.file const post = await Post.create({ name, size, key, url, emotion: req.body.emotion, age: req.body.age, gender: req.body.gender, IP: req.ip, description: req.body.others }) return res.json({ success: true, msg: 'Captcha passed' });
about 4 years ago · Juan Pablo Isaza
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!