upload.js 565 Bytes
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8
// pages/api/upload.js

import fs from "fs";
import path from "path";
import formidable from "formidable";

export default async function handler(req, res) {
  if (req.method === "POST") {
wuhao's avatar
wuhao committed
9 10 11
    const formData = await req.formData();
    // Get the file from the form data
    const file = formData.get("file");
wuhao's avatar
wuhao committed
12
    console.log("====================================");
wuhao's avatar
wuhao committed
13
    console.log(file);
wuhao's avatar
wuhao committed
14
    console.log("====================================");
wuhao's avatar
wuhao committed
15

wuhao's avatar
wuhao committed
16
    res.status(200).json({ data: "sad" });
wuhao's avatar
wuhao committed
17 18 19 20
  } else {
    res.status(405).end(`Method ${method} Not Allowed`);
  }
}