1

Possible Duplicate:
Uploaded image only available after refreshing the page

I'm using primefaces to upload files to my application and it's working but I have a path problem .

I'm using netbeans IDE.

I'm storing the uploaded file under : (Project\web\WEB-INF\photo) as the following code shows :

 public void FileUpload(FileUploadEvent event) throws IOException {
    UploadedFile upfile = event.getFile();
    InputStream in = new BufferedInputStream(upfile.getInputstream());
    ExternalContext extContext =
                          FacesContext.getCurrentInstance().getExternalContext();
    File file = new File(extContext.getRealPath
                     ("//WEB-INF//photo//" + event.getFile().getFileName()));

    FileOutputStream fout = new FileOutputStream(file);
    byte[] bytes = new byte[1024];
    while (in.available() != 0) {
        fout.write(in.read());
    }
    fout.write(bytes);
    fout.close(); .......
} 

and this method works correctly but the uploaded file does'nt exist in the wanted directory (Project\web\WEB-INF\photo) but it's found under the build folder (Project\build\web\WEB-INF\photo) so then when i want to display the photo an error says that the photo does not exist in the directory ,

so any idea ? and why the file is stored under the build not in the wanted directory ??

Community
  • 1
  • 1
MarwaInsat
  • 293
  • 1
  • 4
  • 17
  • 1
    In my answer to [your previous question](http://stackoverflow.com/questions/12715697/how-can-i-display-a-dynamic-photo-in-the-user-details-page) you was also given several links which shows how to do it the right way. Please do not ignore those links. – BalusC Oct 04 '12 at 22:47
  • ok thanks i will try to do it the right way :) – MarwaInsat Oct 04 '12 at 22:53
  • @BalusC I followed the answer that you presented but it's not working for me, it generated an exception not found directory besides the 'File file = new File("/path/to/uploaded/files", filename); ' does not point the C:/ but it points the domain directory of the glassfish server (C:\Users\Me\AppData\Roaming\NetBeans\7.2\config\GF3\domain1\path\to\uploaded) (it was me who created the folder under the domain to enble the run of the application) – MarwaInsat Oct 05 '12 at 09:47
  • Apparently you did actually not prefix the path with `/`. – BalusC Oct 05 '12 at 12:32
  • FileNotFoundException: \path\to\uploaded\photos\blue.png ..... so even after putting this ` ` in the glassfish-web.xml , i still get the exception :( – MarwaInsat Oct 05 '12 at 20:52

0 Answers0