【发布时间】:2019-02-05 19:53:30
【问题描述】:
我试图弄清楚如何编写一种方法来简单地将文件从 webflux 控制器发送到“常规”控制器。
我经常收到一个常见错误,但我尝试过的都没有解决它。
我发送文件的方法:
@GetMapping("process")
public Flux<String> process() throws MalformedURLException {
final UrlResource resource = new UrlResource("file:/tmp/document.pdf");
MultiValueMap<String, UrlResource> data = new LinkedMultiValueMap<>();
data.add("file", resource);
return webClient.post()
.uri(LAMBDA_ENDPOINT)
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData(data))
.exchange()
.flatMap(response -> response.bodyToMono(String.class))
.flux();
}
我正在使用以下端点的 AWS Lambda 中使用它:
@PostMapping(path = "/input", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<List<?>> input(@RequestParam("file") MultipartFile file) throws IOException {
final ByteBuffer byteBuffer = ByteBuffer.wrap(file.getBytes());
//[..]
return new ResponseEntity<>(result, HttpStatus.OK);
}
但我不断得到:
{
"timestamp":1549395273838,
"status":400,
"error":"Bad Request",
"message":"Required request part 'file' is not present",
"path":"/detect-face"
}
从 lambda 返回;
我只是设置了文件的发送不正确,还是我需要在 API 网关上配置一些东西以允许请求参数进入?
【问题讨论】:
标签: java aws-lambda spring-webflux