I've been working on integrating image uploading functionality into my application. I'm currently using NextJS version 13.4.4 along with formidable@v3. However, whenever I attempt to upload an image, I encounter the following error:
error TypeError: req.on is not a function at IncomingForm.parse (webpack-internal:///(sc_server)/./node_modules/formidable/src/Formidable.js:182:13)
Note: This code functions correctly in previous versions prior to next13.
Below is a snippet of the simple form I am using:
"use client";
import React, { useState } from "react";
import Image from "next/image";
import axios from "axios";
type Props = {};
export default function page({}: Props) {
// Code block for handling file upload and displaying selected image.
}
Additionally, here is the API backend code:
import formidable from "formidable";
import { NextApiRequest } from "next";
import path from "path";
import fs from "node:fs/promises";
// Backend API code snippet implementing file upload logic.
I referenced this code from this source. Could use some guidance on adjusting it for the newer NextJS version.