midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.37k stars 574 forks source link

form-data请求中同名array类型参数会被覆盖,只能收到最后一个参数 #3970

Closed kaesi0 closed 2 months ago

kaesi0 commented 2 months ago

Discussed in https://github.com/midwayjs/midway/discussions/3967

Originally posted by **kaesi0** July 24, 2024 ### Describe the problem(描述问题) 在/addTag路由中需要设置数组类型的别名参数alias以及上传文件,所以需要以form-data格式发起请求 我的路由是 ` @Post('/addTag') async addTag(@Files() files, @Fields() fields: AddTagDTO) { return await this.tagService.addTag(fields, files); }` AddTagDTO: `export class AddTagDTO { @Rule(RuleType.string().min(2).max(10).required()) name: string; @Rule(RuleType.array().items(RuleType.string()).single()) alias: string[]; ` 当我以form-data形式发起请求时,比如 ![image](https://github.com/user-attachments/assets/dd67b535-6c78-40a9-bc21-8fc64065e60a) 在服务端解析后的参数中,alias始终只有最后一个值,也就是“别名1”被覆盖了,这可能与服务端的参数解析设定有关,但不清楚是Fields装饰器的bug还是koa-bodyparser的配置问题,如果是koa-bodyparser的配置问题,在哪里能修改? -----------------补充---------------------- 应该是默认的body-parser中间件并不支持解析multipart bodies:https://www.npmjs.com/package/body-parser 我关闭了默认的bodyParser,使用koa-body中间件替换,但是在开启了upload组件的情况下,如果设置koa-body的multipart==true,请求会卡死,应该是与upload组件冲突了,关闭upload组件上传文件和解析数组参数都正常了,但又失去了upload组件好用的自动清理,限制文件格式等功能,请修复一下,如果有修复发布请通知。感谢 ### Midway Versions(Midway 版本) >> Start to check your midway component version... ✓ @midwayjs/faas-typings(not installed) ✓ @midwayjs/fc-starter(not installed) ✓ @midwayjs/serverless-http-parser(not installed) ✓ @midwayjs/async-hooks-context-manager(not installed) ✓ @midwayjs/axios(3.16.5) ✓ @midwayjs/bootstrap(3.16.2) ✓ @midwayjs/bull(not installed) ✓ @midwayjs/bull-board(not installed) ✓ @midwayjs/cache-manager(3.16.5) ✓ @midwayjs/captcha(not installed) ✓ @midwayjs/casbin(not installed) ✓ @midwayjs/casbin-redis-adapter(not installed) ✓ @midwayjs/casbin-typeorm-adapter(not installed) ✓ @midwayjs/code-dye(not installed) ✓ @midwayjs/consul(not installed) ✓ @midwayjs/core(3.16.2) ✓ @midwayjs/cos(not installed) ✓ @midwayjs/cron(3.16.5) ✓ @midwayjs/cross-domain(not installed) ✓ @midwayjs/decorator(not installed) ✓ @midwayjs/etcd(not installed) ✓ @midwayjs/express-session(not installed) ✓ @midwayjs/faas(not installed) ✓ @midwayjs/grpc(not installed) ✓ @midwayjs/http-proxy(not installed) ✓ @midwayjs/i18n(not installed) ✓ @midwayjs/info(3.16.5) ✓ @midwayjs/jwt(3.16.5) ✓ @midwayjs/kafka(not installed) ✓ @midwayjs/leoric(not installed) ✓ @midwayjs/mikro(not installed) ✓ @midwayjs/mock(3.16.5) ✓ @midwayjs/mongoose(not installed) ✓ @midwayjs/mqtt(not installed) ✓ @midwayjs/oss(not installed) ✓ @midwayjs/otel(not installed) ✓ @midwayjs/passport(not installed) ✓ @midwayjs/process-agent(not installed) ✓ @midwayjs/prometheus(not installed) ✓ @midwayjs/prometheus-socket-io(not installed) ✓ @midwayjs/rabbitmq(not installed) ✓ @midwayjs/redis(not installed) ✓ @midwayjs/security(not installed) ✓ @midwayjs/sequelize(not installed) ✓ @midwayjs/session(not installed) ✓ @midwayjs/socketio(not installed) ✓ @midwayjs/static-file(not installed) ✓ @midwayjs/swagger(not installed) ✓ @midwayjs/tablestore(not installed) ✓ @midwayjs/tags(not installed) ✓ @midwayjs/tenant(not installed) ✓ @midwayjs/typegoose(3.16.5) ✓ @midwayjs/typeorm(not installed) ✓ @midwayjs/upload(3.16.5) ✓ @midwayjs/validate(3.16.5) ✓ @midwayjs/version(not installed) ✓ @midwayjs/view(not installed) ✓ @midwayjs/view-ejs(not installed) ✓ @midwayjs/view-nunjucks(not installed) ✓ @midwayjs/web(not installed) ✓ @midwayjs/express(not installed) ✓ @midwayjs/koa(3.16.5) ✓ @midwayjs/ws(not installed) ********************************************************************** >> Check complete, all versions are healthy. **********************************************************************