node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Buffer usage

R0N1n-dev opened this issue · comments

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise):Community
  • Currently blocking your project/work? (yes/no):Yes
  • Affecting a production system? (yes/no):Yes

Context

  • Node.js version: v18.16.0
  • Release Line of Formidable (Legacy, Current, Next):Current
  • Formidable exact version: 3.5.1
  • Environment (node, browser, native, OS): v18.16.0, Brave, Linux, PopOS
  • Used with (popular names of modules): @prisma/client, @cosmicjs/sdk

What are you trying to achieve or the steps to reproduce?

import cosmic from "~~/lib/cosmic.mjs";
import formidable from "formidable";

export default defineEventHandler(async (event) => {
  if ((event.node.req.method = "POST")) {
    const form = formidable({});
    await form.parse(event.node.req, (err, fields, files) => {
      if (err) {
        console.log(err);
        return;
      }
      console.table(files?.file[0]);
      const media = /*files?.file[0]*/ {
        originalname: files?.file[0].originalFilename,
        buffer: files?.file[0].buffer,
      };
      //console.log(media);
      return { media };
    });
    /*console.log(media);
    try {
      const data = await cosmic.media.insertOne({
        media: media,
        folder: "nuxt-test",
      });
      return { Success: true, data };
    } catch (error) {
      console.log(error.message);
    }*/
  }
});

What was the result you got?

None. Coz I cannot get a buffer

What result did you expect?

A buffer Ican use to upload the image coz the cosmic API need a buffer

Search for similar issues and examples