【问题标题】:Trying to read a file from html but getting undefined in nodejs尝试从 html 读取文件但在 nodejs 中未定义
【发布时间】:2020-09-24 23:19:52
【问题描述】:
app.post('/addimage', upload.single('image'), function(request, response){
console.log(request.body)
const body = request.file
console.log(body)
response.redirect('/image')
})
var storage = multer.memoryStorage()
var upload = multer({ storage: storage })




<div class="form-group">
    <label for="image">Choose a image</label>
    <input type="file" class="form-control-file" id="image" name="image">
</div>

第一部分是nodejs代码,第二部分是html表单。 request.body 返回图像文件名,但是当我执行 request.file(s) 时,它只是未定义。我试过了

【问题讨论】:

    标签: html node.js multer


    【解决方案1】:

    已解决需要在表单中添加enctype="multipart/form-data"。应该发布完整的表格以获得更好的帮助。对不起

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-31
      • 2019-01-31
      • 2018-02-04
      • 2022-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-27
      相关资源
      最近更新 更多