文件上传

This commit is contained in:
chaosBreaking
2019-10-10 15:44:59 +08:00
parent f5e9e8dbe6
commit 832b8f2f53
4 changed files with 35 additions and 0 deletions

15
src/utils/form.js Normal file
View 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 });
});
});
}
};