I want to store a image files. Each image files’ names are their fields’ name. I’m using Nextjs
import path from "path";
import multer from 'multer'
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
const latest = await prisma.items.findFirst({
orderBy: {
id: 'desc',
},
});
const latestName = latest.name.replaceAll(" ", "-")
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, '/uploads/')
},
filename: function (req, file, cb) {
cb(null, latestName + '-' + file.fieldname + path.extname(file.originalname))
}
});
const upload = multer({storage : storage})
export const POST = async (req, res) => {
upload.fields([{
name: 'thumbnail', maxCount: 1
}, {
name: 'cover' , maxCount: 1
}])
return NextResponse.json({message : "success"
})
};
export const config = {
api: {
bodyParser: false,
},
};
the message is responsed but files aren’t stored. I thought it’s a problem with the folder path, so I changed a path. So, path is correct, but still, I can’t store the image