我正在尝试使用RequestParts上传带有额外参数的文件。我已成功上传文件;但是,当我尝试添加额外参数时,我会收到错误响应。
我的控制器:
我尝试以两种不同的方式进行POST,但出现了不同的错误:
1)
这个错误的信息是:
它返回以下错误:
我假设第一种方法是正确的;然而,该应用程序支持JSON,所以我不确定我在配置方面缺少什么。我需要在请求中添加什么才能使它正常工作,或者我在消息转换器中漏掉了什么。
注意:不确定这是否重要,但我正在使用Postman测试端点。
我的控制器:
@RequestMapping(value = "/v1/cases/{caseId}/file", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Success uploadFile(
@RequestPart(value="file") MultipartFile file,
@RequestPart(value="fileParameters") FileParameters fileParameters) throws FileNotFoundException, IOException {
我尝试以两种不同的方式进行POST,但出现了不同的错误:
1)
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="file"; filename="myFile"
Content-Type:
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="fileParameters"
{"filePassword":"testPassword", "configuration":{}, "target":null}
----WebKitFormBoundaryE19zNvXGzXaLvS5C
这个错误的信息是:
The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. See 'supportedMediaTypes' in 'additionalInfo' for a list of supported types
2)
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="file"; filename="myFile"
Content-Type:
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="fileParamters[filePassword]"
testPassword
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="fileParamters[configuration]"
{}
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="fileParamters[target]"
null
----WebKitFormBoundaryE19zNvXGzXaLvS5C
它返回以下错误:
"rootExceptionClass": "org.springframework.web.multipart.support.MissingServletRequestPartException",
"rootExceptionMessage": "Required request part 'keyParameters' is not present."
我假设第一种方法是正确的;然而,该应用程序支持JSON,所以我不确定我在配置方面缺少什么。我需要在请求中添加什么才能使它正常工作,或者我在消息转换器中漏掉了什么。
注意:不确定这是否重要,但我正在使用Postman测试端点。