土星:
Iので、Java APIを持っていると私は私のAPIにGET / POSTリクエストを送信するためのcURLコマンドを使用します。私は私のJava APIでSpringbootを使用しています。このような私のcURLコマンドルックス:
curl -X POST \
https://localhost:8443/abc/code/v \
-H 'Content-Type: multipart/form-data' \
-F file=@/path/to/file.txt
そして、この要求を受けて、私のJava Springbootメソッドは次のようになります。
@RequestMapping(method = RequestMethod.POST, value = "/{code}/{v}")
public ResponseEntity<Object> uploadTemplate( //
@ApiParam(value = "code desc") //
@PathVariable final String code, //
@ApiParam(value = "v desc") //
@PathVariable final String v, //
@RequestParam("file") MultipartFile file
) throws IOException {
//log.info("received [url: /tabc/" + code + "/" + v + ", method: POST");
System.out.println("file: "+ file.getName());
}
これは出力します "file: file"
それは似ていないfile.txt
すべてのサーバーにアップロードされます!何が私が間違っているのでしょうか?私はGoogleで調べてきましたが、私はほとんどすべてのものをやっているように見えます。
マルコ・R:
MultipartFile.getName
マルチパート形式でパラメータの名前を返します。
バイトを取得するにはMultipartFile
、使用をfile.getBytes()
そして、あなたがもしMultipartFile
あなたがそのテキストファイルの行のリストを取得するには、このユーティリティメソッドを使用することができ、テキストファイルです。
public List<String> read(MultipartFile file) throws IOException {
InputStreamReader in = new InputStreamReader(file.getInputStream());
try (BufferedReader reader = new BufferedReader(in)) {
return reader.lines().collect(Collectors.toList());
}
}