Question

I have uploaded my maven/spring project on jelastic and using following to save images:

   ServletContext servletContext = request.getSession().getServletContext();
   String absoluteFilesystemPath = servletContext.getRealPath("/");
   byte[] fileData = file.getBytes();
   String name=Trader.getImage();
   if (fileData.length != 0) {
       String fileName =login.getUserName()+".jpeg";
       File f = new File(absoluteFilesystemPath+"\\img\\"+fileName);
       FileOutputStream fileOutputStream = new FileOutputStream(fileName);
       fileOutputStream.write(fileData);
       fileOutputStream.close();
  }

It is working on localhost images are saved in img folder while on server it is saved on absolute path as name "img/xyz.jpeg"

i want to save it on

myproject/img/

It is saving on

myproject
Was it helpful?

Solution

Isn't your \ the wrong way? I'm going to guess that your localhost is Windows?

Jelastic is Linux based, so filesystem paths contain / not \. Maybe try

File(absoluteFilesystemPath+"/img/"+fileName);

Edit: according to File.separator vs Slash in Paths you might want to use File.separator instead for proper platform independence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top