简体   繁体   English

Uncaught TypeError TypeError:无法读取未定义的属性(读取“路径”)

[英]Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'path')

I am new to programming我是编程新手

INDEX.JS索引.JS

 const express = require("express") const path = require("path") const multer = require("multer") const app = express() const maxSize = 1 * 1000 * 1000; app.use(express.static(path.join(__dirname, 'public'))) var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, "uploads") }, filename: function (req, file, cb) { cb(null, file.fieldname + "-" + Date.now()+".pdf") } }) var upload = multer({storage: storage, limits: { fileSize: maxSize }}).array('fileUpload', 2); app.get("/", (req, res) => { res.sendFile(__dirname + "/index.html"); }); app.get("/uploads/:filename", (req, res) => { let filename = req.params.filename; res.sendFile(__dirname + "/uploads/" + filename) }); app.post("/upload",function (req, res, next) { upload(req,res,function(err) { if(err) { res.send(err) } else { let str = `<p>Success, pdf uploaded!</p> <p><a href="${req.file.path}">View File</a></p>`; res.send(str) } }) }) app.listen(9000,function(error) { if(error) throw error console.log("Server created Successfully on PORT 9000") console.log("http://localhost:9000") })

INDEX.HTML索引.HTML

 <!DOCTYPE html> <html> <head> <link href="main.css" rel="stylesheet"> </head> <body> <form action="/upload" enctype="multipart/form-data" method="POST"> <input type="file" name="fileUpload" id="fileUpload" hidden="hidden" multiple /> <br> <button type="button" id="button1">UPLOAD FILES</button> <input type="submit" value="submit" /> </form> <script src="main.js"></script> </body> </html>

MAIN.JS主.JS

 const customBtn = document.getElementById("button1"); const fileUpload = document.getElementById("fileUpload") customBtn.addEventListener("click", function() { fileUpload.click(); }); fileUpload.addEventListener("change", function() { if (fileUpload.value) { customBtn.innerHTML = fileUpload.value.match( /[\/\\]([\w\d\s\.\-\(\)]+)$/ )[1]; } else { customBtn.innerHTML = "No file chosen, yet."; } });

When I run INDEX.js i get the following error Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'path') The pdfs get uploaded to my UPLOADS folder but I still get the error Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'path')当我运行 INDEX.js 时,我收到以下错误Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'path') pdfs 被上传到我的 UPLOADS 文件夹,但我仍然收到错误Uncaught TypeError TypeError: Cannot read properties of undefined (阅读“路径”)

在您的代码所在的文件夹中打开一个终端并尝试运行npm install

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法读取未定义的属性(读取“8”) - Uncaught TypeError: Cannot read properties of undefined (reading '8') 未捕获的类型错误:无法读取未定义的属性(读取“0”) - Uncaught TypeError: Cannot read properties of undefined (reading '0') 未捕获的类型错误:无法读取未定义的属性(读取“0”) - Uncaught TypeError: Cannot read properties of undefined (reading '0') 未捕获的类型错误:无法读取未定义的属性(读取“”) - Uncaught TypeError: Cannot read properties of undefined (reading '') 未捕获的类型错误:无法读取 null 的属性(正在读取“切片”)------ 未捕获的类型错误:无法读取未定义的属性(正在读取“过滤器”) - Uncaught TypeError: Cannot read properties of null (reading 'slice') ------ Uncaught TypeError: Cannot read properties of undefined (reading 'filter') 未捕获的类型错误:无法读取未定义的属性(读取“目标”)和(读取“值”) - Uncaught TypeError: Cannot read properties of undefined (reading 'target') & (reading 'value') 未捕获的类型错误:无法读取未定义的属性(读取“未定义”) - Uncaught TypeError: Cannot read properties of undefined (reading 'undefined') Redux 工具包:未捕获的类型错误:无法读取未定义的属性(读取“类型”) - Redux toolkit: Uncaught TypeError: Cannot read properties of undefined (reading 'type') MUI 警报未捕获类型错误:无法读取未定义的属性(读取“光”) - MUI Alert Uncaught TypeError: Cannot read properties of undefined (reading 'light') 未捕获的类型错误:无法读取未定义的属性(读取“焦点”) - Uncaught TypeError: Cannot read properties of undefined (reading 'focus')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM