#why do i get a POST error when i try to submit a form(application)?
1 messages · Page 1 of 1 (latest)
hey im having a POST error when i try to upload a photo using cloudinary
Done
import prisma from "../../lib/prisma";
import type { NextApiRequest, NextApiResponse } from "next";
import { unstable_getServerSession } from "next-auth";
import { authOptions } from "./auth/[...nextauth]";
import { File } from "@prisma/client";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== "POST") {
res.status(405).send("Method not allowed");
return;
}
const session = await unstable_getServerSession(req, res, authOptions);
if (!session || !session.user) {
res.status(401).send("Unauthorized");
return;
}
if (
!req.body?.title ||
!req.body?.description ||
!req.body?.contributors ||
!req.body?.files
) {
res.status(400).send("Missing required fields");
return;
}
if (req.body.files.length == 0) {
res.status(400).send("Files must not be empty");
return;
}
const { title, description, contributors, files } = req.body;
try {
await prisma.project.create({
data: {
title,
description,
contributors: {
connect: [
{ id: session.user.id },
...contributors.map((c: string) => ({ id: c })),
],
},
files: {
create: files.map((file: File) => ({
url: file.url,
mediaType: file.mediaType,
width: file.width,
height: file.height,
})),
},
},
});
} catch (e) {
console.log(e);
res.status(400).send(`Error creating project: ${e}`);
}
res.end();
}
@echo tendon dont yk ts
yes
can u help me?
Not until you actually post a question lol
All you've done is post pictures of errors with no context
i didnt ask a question
really
POST error when i try to upload a photo using cloudinary how can i solve this
i changed the title lol
@echo tendon wat dont u understand in the question
why do i get a POST error when i try to upload a photo using cloudinary
why do i get a POST error when i try to submit a form(application)?
thanks
Error creating project: Error: Argument data.contributors.connect of type UserWhereUniqueInput needs at least one argument.
i found this in network tab
Check your network tab and see what the response is. You're getting a 400 error which is for "bad request" -- it looks like all of your 400 responses in the server code have a message associated with them, so they should have a 'response'