添加“spring-boot-starter-hateoas”依赖项后上传文件的 Spring-boot Api 端点不起作用

问题描述 投票:0回答:0

我有一个简单的 API 函数来上传类似于以下内容的文件:

@PostMapping(value = "/documents",
             consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public Mono<ResponseEntity<String>> uploadDocument(@RequestPart Mono<FilePart> file){
    
    return storeDocumentService
                    .upload(file)
                    .map(fileLocation->ResponseEntity.ok(fileLocation))
}

代码工作正常并上传文件。当我想通过返回上传文件的链接来使响应更好一些时,问题就来了。为此,我想使用 HATEOAS 'org.springframework.boot:spring-boot-starter-hateoas'。一旦我将依赖项“org.springframework.boot:spring-boot-starter-hateoas”添加到我的“build.gradle”中,端点就会停止工作,我会收到回复:

{
    "timestamp": "2023-02-20T04:28:10.620+00:00",
    "status": 415,
    "error": "Unsupported Media Type",
    "path": "/documents"
}

我也进入日志:

2023-02-20T05:28:10.618+01:00  WARN 2993 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'application/pdf' is not supported]

需要指出的是,我上传了一个标题为“Content-Type:multipart/form-data”的“.pdf”文件。最重要的是,工作代码和非工作代码的唯一变化是我只是添加了对 HATEOAS 'org.springframework.boot:spring-boot-starter-hateoas'

的依赖
spring-boot rest spring-hateoas
© www.soinside.com 2019 - 2024. All rights reserved.