Reputation: 80
Process Multipart CSV File uploaded from Angular 4 using Spring Boot back end?
I have gone through many examples from various sources, none of them provides answer for batch processing csv files uploaded from Web UI using spring batch. All examples process csv files located in resource folder (classpath). Please help me
Upvotes: 0
Views: 907
Reputation: 851
try this, one example ihv been trying recently. in boot you have to upload files from multipart way. thats why its been used here.
Controller
@RequestMapping(method = RequestMethod.POST, value = "/save")
public ReturnFormat uploadCSV(@RequestParam("files") MultipartFile file )
{
return uploadingService.uploadCSV( file );
}
Service class will be like
public void uploadCSV (MultipartFile multipartFile)
{
ReturnFormat rf = new ReturnFormat();
SuccessErrorList selist = new SuccessErrorList();
try
{
File file = convertMultiPartToFile( multipartFile );
}
private File convertMultiPartToFile( MultipartFile file ) throws IOException
{
File convFile = new File( file.getOriginalFilename() );
FileOutputStream fos = new FileOutputStream( convFile );
fos.write( file.getBytes() );
fos.close();
return convFile;
}
Upvotes: 2