formidable icon indicating copy to clipboard operation
formidable copied to clipboard

Question: How to use inside Google Cloud Run?

Open boustanihani opened this issue 5 months ago • 3 comments

Question: How to use inside Google Cloud Run?

Is it possible to use Buffer.from(req.rawBody, "base64") instead of req inside Google Cloud Run =>

const form = new Formidable({
  uploadDir: os.tmpdir(),
  keepExtensions: true,
});
const [fields, files] = await form.parse(Buffer.from(req.rawBody, "base64"));

boustanihani avatar Jul 13 '25 10:07 boustanihani

@boustanihani heya

you should be able to pass request-like object that has a binary req.body and req.headers (nodejs like headers, i think object)

that would be a lot easier and supported with v4. You can try formidable@next with parseMultipart(body, { boundary: 'boundary here' }) or parseMultipartRequest as seen here https://github.com/node-formidable/formidable/issues/1011#issuecomment-3004085611

tunnckoCore avatar Jul 22 '25 21:07 tunnckoCore

Thanks, I will wait until v4 gets released and test this.

boustanihani avatar Jul 22 '25 21:07 boustanihani

@boustanihani I had a need for this as well (I had to preserve the rawBody for some security check). It seems like it's working well with v3 already, as @tunnckoCore mentioned, when you re-construct the request. This worked for me:

  const rawBody = req.body as Buffer;
  return new Promise((resolve, reject) => {
    const form = formidable({
      keepExtensions: true,
    });

    const stream = new Readable();
    stream.push(rawBody);
    stream.push(null);
    (stream as IncomingMessage).headers = {
      ...req.headers,
      'content-length': rawBody.length.toString(),
    };

    form.parse(stream as IncomingMessage, (err, fields, files) => {
     // parsing fields/files here
   }

PaulvanMotman avatar Aug 18 '25 11:08 PaulvanMotman

When will v4 be ready :) ?

boustanihani avatar Dec 22 '25 00:12 boustanihani