图片上传

This commit is contained in:
chaosBreaking
2019-10-10 17:35:11 +08:00
parent 832b8f2f53
commit e04e097115
2 changed files with 15 additions and 1 deletions

View File

@@ -5,6 +5,13 @@ module.exports = {
if (!req) return null;
const form = new formidable.IncomingForm();
Object.assign(form, config);
form.on('fileBegin', function (name, file) {
file.path = file.path.replace(/(?<=\/)\S+(?=\.)/, `${config.tag}_${name}`);
});
form.onPart = function (part) {
if (part.filename && (part.mime !== "image/png" && part.mime !== "image/jpeg")) return 0;
form.handlePart(part);
};
return new Promise((resolve, reject) => {
form.parse(req, function (err, fields, data) {
if (err) return reject(err);