/**
* @typedef {object} UserPhotoUploadRequest
* @property {string} field1 - some field 1
* @property {integer} field2 - some field 2
* @property {string} photo.required - Photo - binary
*/
/**
* POST /photo
* @summary Uploads use photo
* @param {UserPhotoUploadRequest} request.body.required - request body - multipart/form-data
* @returns {boolean} 200 - success
* @returns {string} 400 - error text
* @returns {string} 500 - error text
*/
router.post('/photo', validateRequest(), async (req, res) => {
try {
const form = new multiparty.Form();
form.parse(req, async (err, fields, files) => {
// here we get an error since req object is already read by the validateRequest()
// also we have no way to access parsed fields and files by the validateRequest() call
});
} catch (err) {
res.status(500).send(err.message);
}
}
This happens since multiparty reads the req object stream. A possible solution is to modify the request object inside the validateRequest() call by adding fields and files properties there.
This happens since multiparty reads the req object stream. A possible solution is to modify the request object inside the validateRequest() call by adding fields and files properties there.