Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kaesi0 opened this issue Jul 25, 2024 Discussed in #3967 · 1 comment · Fixed by #3971
Closed

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

kaesi0 opened this issue Jul 25, 2024 Discussed in #3967 · 1 comment · Fixed by #3971

Comments

@kaesi0
Copy link

kaesi0 commented Jul 25, 2024

Discussed in #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
在服务端解析后的参数中,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.
**********************************************************************

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant