上载文本文件问题REST控制器

时间:2019-09-23 14:29:18

标签: micronaut

我尝试将form / multipart-data发送到我的rest控制器端点,但是它总是抛出错误。

我认为最重要的是错误线:

  

未指定必需参数[CompletedFileUpload uploadFiles]

我在控制台中看到传递了文件中的文本,但是方法参数不满足。

邮递员的测试要求:

 @Post(consumes = MediaType.MULTIPART_FORM_DATA)
 public HttpResponse sendCodesToEmails(CompletedFileUpload uploadFile) {}

我的休息控制器

16:23:07.060 [nioEventLoopGroup-1-17] DEBUG i.m.h.server.netty.NettyHttpServer - Server localhost:8080 Received Request: POST /v1/staff/code
16:23:07.061 [nioEventLoopGroup-1-17] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matching route POST - /v1/staff/code
16:23:07.061 [nioEventLoopGroup-1-17] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matched route POST - /v1/staff/code to controller class com.zentity.wakanda.users.codes.api.$StaffCodeApiDefinition$Intercepted
16:23:07.061 [nioEventLoopGroup-1-17] TRACE i.m.h.n.reactive.HandlerPublisher - HandlerPublisher (state: IDLE) received demand: 1
16:23:07.061 [nioEventLoopGroup-1-17] TRACE i.m.h.n.reactive.HandlerPublisher - Demand received for next message (state = DEMANDING). Calling context.read()
16:23:07.062 [nioEventLoopGroup-1-17] TRACE i.m.h.n.reactive.HandlerPublisher - HandlerPublisher (state: DEMANDING) emitting next message: ----------------------------503586631991435845838300
Content-Disposition: form-data; name="emails"; filename="emails.txt"
Content-Type: text/plain

ondrej.schrek@gmail.com
ondrej.schrek@zentity.com
----------------------------503586631991435845838300--

16:23:07.062 [nioEventLoopGroup-1-17] TRACE i.m.h.s.netty.RoutingInBoundHandler - Received HTTP Data for request [POST /v1/staff/code]: content-disposition: form-data; name="emails"; filename="emails.txt"
content-type: text/plain; charset=UTF-8
content-length: 50
Completed: true
IsInMemory: true

16:23:07.064 [pool-1-thread-24] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Found matching exception handler for exception [Required argument [CompletedFileUpload uploadFiles] not specified]: io.micronaut.web.router.StatusRouteMatch@5fdda10c

控制台日志:

def tokenize(text, match=re.compile(b"([idel])|(\d+):|(-?\d+)").match):
    i = 0
    while i < len(text):
        m = match(text, i)
        s = m.group(m.lastindex)
        i = m.end()
        if m.lastindex == 2:
            yield "s"
            yield text[i:i + int(s)]
            i = i + int(s)
        else:
            yield s

1 个答案:

答案 0 :(得分:3)

参数名称必须与零件名称匹配,否则请使用@Part批注。

CompletedFileUpload uploadFile-> CompletedFileUpload emails

@Part("emails") CompletedFileUpload uploadFile