#why do i get a POST error when i try to submit a form(application)?

1 messages · Page 1 of 1 (latest)

echo tendon
#

You'll probably have better luck getting help with a proper question. Please check the posting guidelines in the channel.

near swan
#

hey im having a POST error when i try to upload a photo using cloudinary

near swan
hushed maple
near swan
# hushed maple Can you share the code
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();
}
near swan
#

@echo tendon dont yk ts

echo tendon
#

yes

near swan
echo tendon
#

Not until you actually post a question lol

#

All you've done is post pictures of errors with no context

near swan
#

really

#

POST error when i try to upload a photo using cloudinary how can i solve this

near swan
near swan
#

@echo tendon wat dont u understand in the question

echo tendon
near swan
#

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)?

near swan
near swan
#

Error creating project: Error: Argument data.contributors.connect of type UserWhereUniqueInput needs at least one argument.

#

i found this in network tab

echo tendon
# near swan

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'