Question: How to use inside Google Cloud Run?
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 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
Thanks, I will wait until v4 gets released and test this.
@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
}
When will v4 be ready :) ?