文件上传(前+后)
Willem Zhang Lv6

后端

使用node.js的express框架

中间件:
body-paresr 添加req.body 支持四种解析器(urlencoded json。。。) 不支持formdata

需要multer中间件进行 支持formdata

模块:
fs.rename 文件重命名
path.parse 路径解析
使用以上模块实现文件的重命名

上传文件后,由于使用了multer,所以req会有req.files属性 其中req.files.path没有扩展名 需要用path.parse解析req.files.originalname获取扩展名后拼接,从而使得保存的文件有扩展名

ref

https://blog.csdn.net/zhouzhiwengang/article/details/108604811

https://www.jianshu.com/p/9b3a4b81d73a

  • Post title:文件上传(前+后)
  • Post author:Willem Zhang
  • Create time:2022-04-14 23:43:36
  • Post link:https://ataraxia.top/2022/04/14/文件上传(前-后)/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments