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')
        }
      })
目录
相关文章
|
9月前
MultipartFile转为File
MultipartFile转为File
fetch上传文件报错的问题(multipart: NextPart: EOF)
技术栈 后台: gin(golang) 前端: react+antd+dva 问题 前端这边使用fetch发送http请求的时候,后端解析formData报错: multipart: NextPart: EOF 分析问题 原因是上传文件太小了Content-Length数量太小了,尝试将headers里这字段的value变大,发现实际的请求依然是较小值。
|
1月前
|
JavaScript
Component name “header“ should always be multi-word
Component name “header“ should always be multi-word
|
3月前
|
XML Java Maven
如何将MultipartFile转换为File
该文介绍了MultipartFile(Spring框架)与File(Java标准库)的区别,主要讨论了如何将MultipartFile转换为File的三种方法:使用`transferTo`、`FileOutputStream`和Java NIO,并提到了File转MultipartFile常用于测试,可通过MockMultipartFile实现。
|
3月前
|
应用服务中间件 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
101 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
77 0
Posted content type isn't multipart/form-data
Posted content type isn't multipart/form-data
473 0
Circular view path [addKnowledge]: would dispatch back to the current handler URL
报错日志: {"timestamp":1526565246776,"status":500,"error":"Internal Server Error","exception":"javax.
3558 0
|
Java 索引 Spring
Circular view path xxx would dispatch back to the current handler URL
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/79700275 ...
5455 0