java - File Upload with spring data - gridfs -


Hi I am trying to upload a file using spring data. When I try to upload the file, I get an exception.

Try out my code for file upload

  {file file = new file (this.TEMPORARY_FILES_DIRECTORY, Calendar.getInstance () .getTimeInMillis () + "_" + Filenameandrescreed); WriteByteArrayToFile (file, form.getFile). GetBytes ()); FileInputStream inputstream = new FileInputStream (file); Gridface file gridfile = gridfomestemplate.store (inputstream, "test page"); Property Image IMG = New Property Image (); Img.setPropertyUid (gridFSFile.getFilename ()); ImagesRepository.save (img); } Hold (FileNotFoundException E) {// TODO Auto generated blocking block e.printStackTrace (); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); }  

Where TEMPORARY_FILES_DIRECTORY = New file ("/ home / temporary /");

I'm getting the exception

  java.io.ioException: debugging  FileUtils  class      at  

file '/ home / temp / 1392807425028_file' can not be created

  If (parent.mkdirs () == incorrect) {new IOException ("file" "+ file +" 'could not be created'); } Parent.mkdirs () is incorrect.  

Can anyone tell me this code what's wrong with this code?

Are you sure this is / home / temp and not < Code> / home / user name / temporary ? You can not create a directory outside your home directory if you want to store files inside your home directory, then something like Systen.getProperty ("user.home") + "/ temp" Try it. Anyway, why did not you choose your own / tmp on your temporary directory?


Comments