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

267
Views
obtengo un error cuando intento enviar un archivo en el siguiente servidor js

Soy nuevo en el servidor nextjs, estoy tratando de obtener el archivo en el backend pero no estoy definido, en mi consola, vi este error Error: SyntaxError: Unexpected end of JSON input el archivo en mi estado con éxito pero cuando intente enviarlo en el backend, muestra ese error.

mi backend

 import type { NextApiRequest, NextApiResponse } from "next"; const multer = require("multer"); const path = require("path"); const xlsx = require("node-xlsx"); const fileupload = require("express-fileupload"); var bodyParser = require("body-parser"); const uploadFile = multer().single("image"); type Data = { name: string; }; var storage = multer.diskStorage({ destination: function (req: any, file: any, cb: any) { cb(null, path.resolve(__dirname, "uploads")); }, filename: function (req: any, file: any, cb: any) { cb(null, file.fieldname + "_" + Date.now() + "_" + file.originalname); }, }); const uploads = multer({ storage: storage }); export default function handler(req: any, res: NextApiResponse<Data>) { uploadFile(req, res, function (err: any) { const file = req.files; // const filename = file.name; // const worksheetsArray = xlsx.parse(filename); // parses a file console.log(file); res.status(200).json(file); }); }

aquí está mi función uploadFile en la interfaz:

 const uploadFile = async (e: any) => { e.preventDefault(); const formData = new FormData(); formData.append("file", file); formData.append("fileName", fileName); fetch("/api/hello", { method: "POST", body: formData, }) .then((response) => response.json()) .then((data) => { console.log(data); }) };
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!