Postman - POST multipart/form-data


说明

  • 以POST方式提交表单

案例

  • 方法选择POST
  • 再 body 处选择form-data
  • 多个表单内容,可以选择文本,也可以选择文件。
  • 都是以 Key-Value 的方式上传,然后再服务器端接收。

// micronaut 2.x

@Post(value = "/test4", consumes = MediaType.MULTIPART_FORM_DATA, produces = MediaType.TEXT_PLAIN)
Single<HttpResponse<String>> upload(StreamingFileUpload file,String other) {
    File tempFile = File.createTempFile(file.filename, "temp")
    Publisher<Boolean> uploadPublisher = file.transferTo(tempFile)
    Single.fromPublisher(uploadPublisher)
            .map({success ->
                if(success){
                    HttpResponse.ok("Uploaded" + other)
                } else {
                    HttpResponse.status(HttpStatus.CONFLICT)
                    .body("UploadFailed")
                }
            })
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM