文件上传
This commit is contained in:
15
src/utils/form.js
Normal file
15
src/utils/form.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const formidable = require('formidable');
|
||||
|
||||
module.exports = {
|
||||
async parseForm (req, config) {
|
||||
if (!req) return null;
|
||||
const form = new formidable.IncomingForm();
|
||||
Object.assign(form, config);
|
||||
return new Promise((resolve, reject) => {
|
||||
form.parse(req, function (err, fields, data) {
|
||||
if (err) return reject(err);
|
||||
else return resolve({ fields, data });
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user