1

I am using Apache common CSV

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

Code to write a CSV into a 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();
}

Now I have a feign call to save file as:

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

How can I convert the ByteArrayOutputStream to a MultipartFile object, so that I am able to use the csv file in my Feign call?

RustyTheBoyRobot
  • 5,891
  • 4
  • 36
  • 55
Shahid Ghafoor
  • 2,991
  • 17
  • 68
  • 123
  • Please have a look at [this](https://stackoverflow.com/questions/18381928/how-to-convert-byte-array-to-multipartfile) – m4gic Oct 02 '18 at 09:29

0 Answers0