【发布时间】:2021-11-09 15:16:18
【问题描述】:
这是我拥有的端点:
@PostMapping(value = "/file-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public List<FileReference> handleFileUpload(
@RequestPart(value = "file", name = "file") MultipartFile[] file, @ApiIgnore HttpSession session) {
return service.handleFileUpload(
Arrays.stream(file).map(MultipartFileWithUUID::new).collect(Collectors.toList()),
session);
}
这是在 swagger.json (swagger 2.0) 中生成的端点:
...
"post": {
"tags": [
"damage-report-controller"
],
"summary": "handleFileUpload",
"operationId": "handleFileUploadUsingPOST",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "file",
"in": "formData",
"required": false,
"type": "array",
"items": {
"type": "file"
},
"collectionFormat": "multi"
}
],
...
这是生成的函数:
public handleFileUploadUsingPOST(file?: Array<Blob> ...) {
let headers = this.defaultHeaders;
header settings etc...
// to determine the Content-Type header
const consumes: string[] = [
'multipart/form-data'
];
const canConsumeForm = this.canConsumeForm(consumes);
let formParams: { append(param: string, value: any): any; };
let useForm = false;
...
if (useForm) {
formParams = new FormData();
} else {
formParams = new HttpParams({encoder: this.encoder});
}
...
}
我的错误是415: Unsupported media type.
我不知道它应该如何正确生成,但我将 let useForm; 更改为 true 并且它可以工作,
所以我猜let useForm = canConsumeForm(consumes) 因为canConsumeForm 返回一个布尔值。
我应该改变什么才能正确生成?
【问题讨论】:
标签: java angular spring typescript swagger