2017-10-04 45 views
0

我已经设置了一个REST API,它允许从批处理输入处具有CSV的POST方法启动Spring批处理作业,但我不知道因为我不能在我的项目maven的src/main/resources中写入csv,所以我知道它在这里是必须写的,因为在生产中,那里存在的文件将在webapp/classes中/ 要使用的。从post方法上载src/main/resources中的csv

byte[] fileBytes = Base64.decodeBase64(cleanFile); 
    Files.write(Paths.get(getClass().getClassLoader().getResource("/").toURI()), fileBytes); 

生成一个:

"message": "status 500 reading SalesClient#uploadCsv(Base64FileDTO); content:\n{\"timestamp\":1507151307711,\"status\":500,\"error\":\"Internal Server Error\",\"exception\":\"java.io.FileNotFoundException\",\"message\":\"class path resource [bonjour.csv] cannot be resolved to URL because it does not exist\",\"path\":\"/sales/upload\"}", 

回答

1

你需要将文件写入到某种形式的临时位置。在本地工作时,临时目录通常适用于此目的。