Next.js Discord

Discord Forum

Next Api Image Transfer

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Hi! I am trying to use NextJs Apis. I need to transfer data from my service page to the Api end point.
const formData = new FormData();
        image && formData.append("image", image);
        formData.append("name", name);
        formData.append("description", description);
        formData.append("category", category);
        formData.append("price", price.toString());

        const response = await fetch("/api/addProductApi", {
            method: "POST",
            body: formData,
        });

        if (!response.ok) {
            throw new Error("Failed to add product");
        }

what is the best way to receive this data inside the Api, I googled and found the formidable library, I am using it but i have no idea about it, is there any other way? Also by formidable, I am getting Image as .file extension instead of .png. I have been looking for solutions but could not find any.

0 Replies