将CSV文件写入MultipartFile

时间:2018-10-02 09:23:34

标签: java spring csv multipart netflix-feign

我正在使用Apache通用CSV

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-csv</artifactId>
    <version>1.5</version>
</dependency>

将CSV写入ByteArrayOutputStream

的代码
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final CSVFormat format = CSVFormat.DEFAULT;
final CSVPrinter csvPrinter;
try {
  csvPrinter = new CSVPrinter(new PrintWriter(out), format);
  csvPrinter.printRecord("12,ABC,XYZ");
  csvPrinter.printRecord("13,LMN,PQR");
  csvPrinter.flush();
  csvPrinter.close();
} catch (IOException e) {
  e.printStackTrace();
}

现在我有个假电话将文件另存为:

ResponseEntity<ObjectResponseBo> uploadFile(@RequestHeader("Authorization") String var1, @RequestParam("file") MultipartFile var2);

如何将ByteArrayOutputStream转换为MultipartFile对象,以便能够在Feign调用中使用csv文件?

0 个答案:

没有答案