基于基于ExpressJS框架的文件上传
发布于 11 年前 作者 miracle123 4670 次浏览 最后一次编辑是 8 年前

请问谁有用基于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);
   }

};

谢谢,请问那个html代码要写在js代码里吗,还是直接运行那个html代码,我直接运行了html代码,显示如图enter image description here

后台我又运行那个js代码,没有任何信息输出 能告诉我为什么吗?

那个JS是需要在Node下启动的. 比如 node server.js

回到顶部