Error_ Multipart_ Boundary not foun

简介: Error_ Multipart_ Boundary not foun

前端使用 axios put 请求进行文件上传, Node 服务端报错 Error: Multipart: Boundary not found.

server is running .  http://:::3000
Error: Multipart: Boundary not found
    at new Multipart (/home/w/my/project-exercise/FileServer/node_modules/busboy/lib/types/multipart.js:58:11)
    at Multipart (/home/w/my/project-exercise/FileServer/node_modules/busboy/lib/types/multipart.js:26:12)
    at Busboy.parseHeaders (/home/w/my/project-exercise/FileServer/node_modules/busboy/lib/main.js:71:22)
    at new Busboy (/home/w/my/project-exercise/FileServer/node_modules/busboy/lib/main.js:22:10)
    at multerMiddleware (/home/w/my/project-exercise/FileServer/node_modules/multer/lib/make-middleware.js:33:16)
    at Layer.handle [as handle_request] (/home/w/my/project-exercise/FileServer/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/w/my/project-exercise/FileServer/node_modules/express/lib/router/index.js:317:13)
    at /home/w/my/project-exercise/FileServer/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/w/my/project-exercise/FileServer/node_modules/express/lib/router/index.js:335:12)
    at next (/home/w/my/project-exercise/FileServer/node_modules/express/lib/router/index.js:275:10)

Node 服务端使用其他方式上传测试通过, 前端 vue上传代码如下

      let file = document.getElementById('file').files[0]
      console.log(file)
      this.axios.put('http://192.168.xxx.xxx:3000/file_upload_put', file, {
        headers: {
          'Content-Type': 'multipart/form-data'
        },
        transformRequest: [function (data) {
          return data
        }],
        onUploadProgress: progressEvent => {
          let complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%'
          console.log('complete: ', complete)
        }
      })
      .then((response) => {
        if (response.status === 200) {
          console.log('success upload')
        }
      })

解决方式

没有传递 formData 对象导致服务端报错, put 请求中把 file 对象添加到 formData , 直接传递 formData 对象就可以正常上传了

      let file = document.getElementById('file').files[0]
      console.log(file)
      let formData = new FormData()
      formData.append('image', file)
      this.axios.put('http://192.168.xxx.xxx:3000/file_upload_put', formData, {
        headers: {
          'Content-Type': 'multipart/form-data'
        },
        transformRequest: [function (data) {
          return data
        }],
        onUploadProgress: progressEvent => {
          let complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%'
          console.log('complete: ', complete)
        }
      })
      .then((response) => {
        if (response.status === 200) {
          console.log('success upload')
        }
      })
目录
相关文章
fetch上传文件报错的问题(multipart: NextPart: EOF)
技术栈 后台: gin(golang) 前端: react+antd+dva 问题 前端这边使用fetch发送http请求的时候,后端解析formData报错: multipart: NextPart: EOF 分析问题 原因是上传文件太小了Content-Length数量太小了,尝试将headers里这字段的value变大,发现实际的请求依然是较小值。
|
2月前
|
前端开发 Java
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
70 0
|
6月前
|
应用服务中间件 Linux
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes
153 0
913 error Component name “home“ should always be multi-word vuemulti-word-component-names
913 error Component name “home“ should always be multi-word vuemulti-word-component-names
103 0
使用parted创建大分区时 mkpart Warning: The resulting partition is not properly aligned for best performance.
fdisk不能创建大于2T的分区,创建大分区得用parted,我在用parted创建分区时遇到下面的警告提示
234 0
|
机器学习/深度学习 传感器 编解码
翻译:Multi-scale Multi-path Multi-model Fusion Nerwork
M3Net: 多尺度多路径多模型融合网络及其在 RGB-D 显着目标检测中的应用实例
200 0
|
Windows
Illegal character in opaque part at index
Illegal character in opaque part at index
Posted content type isn't multipart/form-data
Posted content type isn't multipart/form-data
520 0