基于基于ExpressJS框架的文件上传
请问谁有用基于ExpressJS框架的文件上传的完整代码呀,我这怎么老是没有数据
3 回复
html
<form id="uploadImgForm" class="form-upload" action="/topic/uploadTopicImg" method="post" enctype="multipart/form-data">
<legend>Upload topic image</legend>
<label>topic image file</label><input name="uploadImg" placeholder="topic image file" type="file"/>
<button type="submit" class="btn btn-primary">Upload image</button>
</form>
js
exports.uploadTopicImg = function(req,res,next){
var file = req.files && req.files.uploadImg;
if (!file) {
res.send({ status: 'failed', message: 'no file' });
return;
}else{
console.log("file name:"+file.name);
console.log("file path:"+file.path);
}
};