ReactJSアプリケーションの魔法使いからポストを送信しています。jsonオブジェクトマップとファイルがアップロードされています。いくつかのオブジェクトを持つPOST jsonとReactJSからRESTへのファイルSpringサーバー
どこ
this.state = {map: {title: "Title", layers: [...] etc.}, files: [file1]}
私はFileReaderInputからFILE1を取得していますが、それは、HTMLの入力タイプのファイルからファイルとまったく同じです。このファイルには、フィールドlastModified、lastModifiedDate、name、size、type、webkitRelativePath、__proto_があります。
そして、私のRESTサーバー上の
私はこれを持っている:public class CreateMapWrapper {
private com.gismaps.pojos.Map map;
private Set<MultipartFile> files;
public Map getMap() {
return map;
}
public void setMap(Map map) {
this.map = map;
}
public Set<MultipartFile> getFiles() {
return files;
}
public void setFiles(Set<MultipartFile> files) {
this.files = files;
}
}
私は私のMapオブジェクトとヌルファイルの配列を送るよすべてが正常に動作します
@RequestMapping(value = "/maps", method = RequestMethod.POST)
public @ResponseBody
HttpStatus add(@RequestBody CreateMapWrapper wrapper) throws IOException, InterruptedException {
System.out.println(wrapper.getMap());
System.out.println(wrapper.getFiles());
return HttpStatus.OK;
}
。リクエストはCreateMapWrapperにマップされ、Mapとヌルの配列を出力します。
しかし、私は配列にファイルを配置することだ、私は例外を取得:
WARN 4348 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Can not construct instance of org.springframework.web.multipart.MultipartFile: abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: [email protected]; line: 1, column: 577] (through reference chain: com.gismaps.CreateMapWrapper["files"]->java.util.HashSet[1]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.springframework.web.multipart.MultipartFile: abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: [email protected]; line: 1, column: 577] (through reference chain: com.gismaps.CreateMapWrapper["files"]->java.util.HashSet[1])
間違っていますか?それはRESTでマッピングされたものですか、またはファイル形式を送信していますReact in wrong way?このようなものを投稿することはできますか?
私はおそらく何か愚かなことをしていますが、私はSpring RESTにファイルをアップロードすることを決してしていませんでした。
方法MultipartFile Interfaceのインスタンスを作成する予定ですか? –