简体   繁体   中英

Handling uploaded files in Spring Boot

I am making a spring boot application and I want to be able to upload image files in a form, save them somewhere on the server and the display these images. I managed to get the files using MultipartFile into my controller, however I am not sure how to save the files locally so that I can use them later.

I am guessing I have to somehow save the files in the resources directory so I can access them in my views. I will also be hosting my application on heroku and I am not sure what kind of access to the file system I have there.

Can somebody point me towards a solution?

一旦有了MultipartFile,就可以使用FileCopyUtils.copy静态方法将其上传到指定目录:

FileCopyUtils.copy(multipartFile.getBytes(), new File("src/main/resources"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM