I'm using Spring Boot and i created a web service for photos upload. for saving files, i used absolute path "/uploads", but it signals that this location's not exist, so i processed by using java path, src/... in local server, that's working very well, but after hosting it on heroku server, images are not uploading. after adding an elements, the src of pictures is not exist.
this is the webservice:
//image /////////////////////////////////////////////////////////////////////
private final Logger log = LoggerFactory.getLogger(this.getClass());
@PostMapping("/")
@RequestMapping(value="/transfererImage", method = RequestMethod.POST)
public void transfererImage(@RequestParam("file") MultipartFile file, @RequestParam("nom") String nom) throws Exception{
String nomFichier="";
try {
nomFichier = nom;
byte[] bytes = file.getBytes();
ClassLoader classLoader = getClass().getClassLoader();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream (new FileOutputStream(new File("src/main/resources/static/images/"+nomFichier)));
bufferedOutputStream.write(bytes);
bufferedOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.info("une erreur est produite lors de la lecture de fichier"+ nomFichier);
}
}
thank you
I solved this problem by using this method:
System.getProperty("user.dir"))
it returns root folder of the project.
Thank you.