You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like formidable-serverless, it really solved my pain with Firebase functions.
It is used as following:
const formidable = require("formidable-serverless");
function getBodyFields(req) {
var form = new formidable.IncomingForm();
return new Promise((resolve, reject) => {
form.parse(req, (err, fields) => {
if (err) reject(err);
else if (Object.keys(fields).length === 0) reject(new Error("No data to upload."));
else resolve(fields);
});
});
}
api.post(apiPath, async (req, res) => {
try {
const { base64, width, height, ext } = await getBodyFields(req);
} catch (error) {
console.error(error);
res.status(500).send(error);
}
});
Having sent an empty request without any field and file the unhandled error happened:
TypeError: this._parser.write is not a function
at IncomingForm.write (/functions/node_modules/formidable/lib/incoming_form.js:159:34)
at IncomingForm.formidable.IncomingForm.parse (/functions/node_modules/formidable-serverless/lib/index.js:58:10)
at Promise (/functions/api.js:114:10)
at new Promise ()
at getBodyFields (/functions/api.js:113:10)
at api.post (/functions/api.js:31:50)
at Layer.handle [as handle_request] (/functions/node_modules/express/lib/router/layer.js:95:5)
at next (/functions/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/functions/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/functions/node_modules/express/lib/router/layer.js:95:5)
"Unhandled" means that error was not cought with neither if (err) reject(err);
nor if (Object.keys(fields).length === 0) reject(new Error("No data to upload."));
It would be good to catch this error in callback function as err.
Thank you!
The text was updated successfully, but these errors were encountered:
I like formidable-serverless, it really solved my pain with Firebase functions.
It is used as following:
Having sent an empty request without any field and file the unhandled error happened:
"Unhandled" means that error was not cought with neither
if (err) reject(err);
nor
if (Object.keys(fields).length === 0) reject(new Error("No data to upload."));
It would be good to catch this error in
callback
function aserr
.Thank you!
The text was updated successfully, but these errors were encountered: