Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer usage #962

Closed
R0N1n-dev opened this issue Jan 2, 2024 · 2 comments
Closed

Buffer usage #962

R0N1n-dev opened this issue Jan 2, 2024 · 2 comments
Labels

Comments

@R0N1n-dev
Copy link

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

@R0N1n-dev R0N1n-dev added the bug label Jan 2, 2024
@GrosSacASac
Copy link
Contributor

Search for similar issues and examples

@tunnckoCore
Copy link
Member

tunnckoCore commented Mar 11, 2024

@R0N1n-dev

I think you can check this example https://github.com/node-formidable/formidable/blob/master/examples/forceBuffer.js

Or you can try formidable-mini which is trimmed down version of formidable - just the parser and exposes a FormData/File API, thus meaning the "files" there are regular Web API Files, so you can file.arrayBuffer() (arraybuffer/uint8array) to Cosmic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants