快递(使用multer)错误:多部分:未找到边界,请求由POSTMAN发送 [英] express (using multer) Error: Multipart: Boundary not found, request sent by POSTMAN

查看:124
本文介绍了快递(使用multer)错误:多部分:未找到边界,请求由POSTMAN发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:仅当我在Postman中使用表单数据主体表单(由于我要在文本字段旁边发送文件而必须使用该表单)时,我得到:

Error: Multipart: Boundary not found.

当我使用x-www-form-urlencoded时,一切正常. (将body-parser用作中间件的当然)

when I use x-www-form-urlencoded everything is ok. (ofcourse when body-parser is used as middleware)

这是请求内容:(邮递员制作)

This is Request Content: (made by Postman)

POST /test HTTP/1.1
Host: localhost:3000
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache-Control: no-cache
Postman-Token: 61089a44-0b87-0530-ca03-a24374786bd1

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="test"

a simple word
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="data"

good
------WebKitFormBoundary7MA4YWxkTrZu0gW--

index.js:

var express = require('express');
var app = express();

var multer = require('multer');
var upload = multer();

app.post('/test', upload.array(), function (req, res, next) {
    console.log(req.body.test);
    console.log(req.body);
});

app.listen(3000, function () {
    console.log('app started');
});

推荐答案

我找到了解决方案.我只需要防止邮递员发送Content-Type标头.所以我只是将其从请求标头中删除.

I found the solution. I only had to prevent Postman to send a Content-Type header. So I just removed it from request headers.

这篇关于快递(使用multer)错误:多部分:未找到边界,请求由POSTMAN发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆