0.1.6 • Published 6 months ago
nodejs-form-parse v0.1.6
var { form_parse, form_parse_multi, remove_images, remove_files } = require('nodejs-form-parse');
function test(req, res){
var options = {
multiples : true,
uploadDir : "./public/",
resize : {
width : 50, // or "auto"
height : 50 // or "auto"
}
};
form_parse(req, options)
.then(body => {
// if multiple == true -> body.images [ "", "" ]
// if multiple == false -> body.image ""
res.json({body});
})
.catch(err => {
// err
res.json({err});
});
remove_images({ path : "./public/", image }); // or images array [ "img.png" ]
remove_files({ path : "./public/", file }); // or files array [ "file.txt" ]
}
function test_multi(req, res){
var options = {
multiples : true, // default true
uploadDir : "./public/",
config : {
poster : {
uploadDir : "./public/poster/", // not required
resize : {
width : 50, // or "auto"
height : 60 // or "auto"
}
},
galery : {
uploadDir : "./public/galery/",
resize : {
width : "auto",
height : 70 // or "auto"
}
}
}
};
form_parse_multi(req, options)
.then(body => {
// body.poster []
// body.galery []
res.json({body});
})
.catch(err => {
res.json({err});
});
}
module.exports = { test, test_multi }