Your directory structures look messed up.Your uploads directory in fileUpload.jsis referring to a directory in ./api/middleware/uploads when it should be referencing ./utils/uploads (the paths relative to the module are incorrect).// fileUpload.jsconst multer = require("multer");const path = require("path");const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, path.resolve(__dirname, `..${path.sep}..${path.sep}`, `${path.sep}utils${path.sep}uploads`); }, __ dirname 返回当前文件所在的目录.因此,在这种情况下,它将是 middleware .(我根据您的 Product.js 文件中的要求推论得出).__dirname returns the directory that the current file is in. So in this case it will be middleware. (I am deducing this based on the require in your Product.js file).尝试通过指向要从其提供静态文件的目录来修复 fileUpload.js 中 uploads 目录的路径.Try fixing the path to the uploads directory in the fileUpload.js by pointing at the same directory that the static files are being served from.此外,我在聊天中看到 Arya 开始于您,您现在设法使其在* nix操作系统上而不是Windows上运行.Also, I seen in the chat that Arya started with you that you are now managing to get it working on a *nix OS but not on windows.尝试更改路径分隔符,以使用 path 模块中的 path.sep .上面 Arya 的解决方案看起来不错,也就是说,相对于静态 uploads 目录,文件路径现在看起来都固定了.我已经根据您发布的原始代码和您提供的目录结构更新了使用path.sep的答案.Try changing your path separators to use path.sep from the path module. Arya's solution above looks good, i.e. the file paths now all look fixed relative to the static uploads directory. I have updated my answer to use path.sep based on the original code that you published and the directory structure that you provided. 这篇关于“消息":"ENOENT:没有这样的文件或目录,打开'E:\\ astrology \\ utils \\ uploads \\ 1600798534862qf.png'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-06 16:16