我使用了以下内容: How to pass body @RequestBody and @RequestParam in same request
它与String一起工作,但是如果我使用的是自定义对象类,则会收到415-http响应,其中包含:application / octett-stream ..
uploadDio() async {
Dto upload = Dto(
"name",
"test",
51123123123,
52123123123,
30);
Response response;
Dio dio = new Dio();
FormData formData =
new FormData.from({"token": "token", "image": new UploadFileInfo(image, "image.png")});
var jsonEncoded = json.encode(upload.toJson());
formData.add("dto", jsonEncoded);
print("dto json: $jsonEncoded");
response = await dio.post("url", data: formData);
print(response.statusCode);
}
那么如何将带有令牌和自定义对象类的文件发布到后端?
这是后端功能:
@PostMapping(value="/uploadDto", consumes = {"multipart/form-data"})
@ResponseBody
public StatusResponse createDto(@RequestPart("dto") @Valid @NotNull Dto dto, @RequestPart("image") @Valid @NotNull MultipartFile image)
任何帮助表示赞赏:)