In my Spring MVC application, there is a need to upload user files. The application runs on tomcat. On the local machine, I specify the path to the folder for saving files so imagesUrl = c: / images / (in the file my.properties) and in the controller I get this property as a path. Everything is working.
Next, I launch the application on the server (Ubuntu 14.04), and in the settings file I change the value to imagesUrl = / images / . Pre-created the folder /images and prescribed it chmod ugo+rw . The catalina.out errors only when trying to get files from the directory. What could be the problem?
EDITED: save:
public String save(List<Image> images) { if (images.size() == 0) return null; String imagesUrl = generalProperties.getProperty("imagesUrl"); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); for ( int i = 0; i < images.size(); i++ ) { Image image = images.get(i); String location = imagesUrl + image.getUser() + "/" + image.getTitle(); File pathFile = new File(location); if (!pathFile.exists()) { pathFile.mkdir(); } pathFile = new File(location + "/" + image.getName()); try { image.getFile().transferTo(pathFile); } catch (IOException e) { e.printStackTrace(); } session.save(image); if ( i % 20 == 0 ) { session.flush(); session.clear(); } } tx.commit(); session.close(); return "Advert saved successfully"; } so I get:
@RequestMapping(value = "/imageDisplay", method = RequestMethod.GET) public void showImage(HttpServletResponse response, HttpServletRequest request, Model model, @RequestParam("advertId") Integer advertId, @RequestParam("user") String user, @RequestParam("fileName") String fileName) throws ServletException, IOException, SQLException { String imagesUrl = generalProperties.getProperty("imagesUrl"); File file = new File(imagesUrl + user + "/" + advertService.getAdvertById(advertId).getTitle() + "/" + fileName); InputStream inputStream = null; inputStream = new FileInputStream(file); FileCopyUtils.copy(inputStream, response.getOutputStream()); }