图片上传
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user