Question

Im currently debugging a webapp, where the user is supposed to upload a file which is then stored temporarily on the server and send via E-Mail to an administrator.

The app runs on a tomcat 8 in a linux server environment. The class from where the error occurs looks like follows:

@Service
public class BugReportBo implements IBugReportBo {

  ...

  @Value("${app.temp.folder}")
  private Resource temp;

  ...

  private File byteArrayToFile(final byte[] lob, final String string) throws IOException {
    final int locatorStartPos = 6;
    String uri = temp.getURI().toString().substring(locatorStartPos);

    //uri: var/lib/tomcat/webapps/prototype/res/temp/
    //string: temp0.jpg

    // convert array of bytes into file
    File f = new File(uri + string);
    FileOutputStream fileOuputStream = new FileOutputStream(uri + string);
    fileOuputStream.write(lob);
    fileOuputStream.close();
    return f;
  }
}

The error is thrown from FileOutputStream fileOuputStream = new FileOutputStream(uri + string);.

The Exception is a FileNotFoundException (message:"var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg (Datei oder Verzeichnis nicht gefunden)").

Everything seems to be ok to me as the folder is where it is supposed to be and the path seems to be fine as well.

Any ideas?

Was it helpful?

Solution

var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg

You forget the first '/', so the path is understand like a relative path, instead of an absolute path.

/var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg

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