Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Upload Component - File Not Found
Using the upload Component I receive a java.io.FileNotFoundException when trying to create a new FileOutputStream. I have created the file just beforehand and the path to the file is correct.
@Override
public OutputStream receiveUpload(String filename, String mimeType) {
FileOutputStream fos = null;
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
file = new File(basepath + "/WebContent/WEB-INF/images/" + filename);
try{
fos = new FileOutputStream(file);
} catch (final IOException e){
e.printStackTrace();
return null;
}
return fos;
}
stacktrace from attempting to upload a png image:
java.io.FileNotFoundException: C:\Java\Workspace\Bleeding Edge\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\CallSystem\WebContent\WEB-INF\images\twit_400x400.png (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:145)
at com.callsystem.UI.newCustomerCallView.receiveUpload(newCustomerCallView.java:279)
at com.vaadin.ui.Upload$2.getOutputStream(Upload.java:1139)
at com.vaadin.server.communication.FileUploadHandler.streamToReceiver(FileUploadHandler.java:547)
at com.vaadin.server.communication.FileUploadHandler.handleFileUploadValidationAndData(FileUploadHandler.java:456)
at com.vaadin.server.communication.FileUploadHandler.doHandleSimpleMultipartFileUpload(FileUploadHandler.java:403)
at com.vaadin.server.communication.FileUploadHandler.handleRequest(FileUploadHandler.java:285)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
08-Aug-2016 10:41:58 com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
com.vaadin.server.UploadException: Upload failed
at com.vaadin.server.communication.FileUploadHandler.streamToReceiver(FileUploadHandler.java:627)
at com.vaadin.server.communication.FileUploadHandler.handleFileUploadValidationAndData(FileUploadHandler.java:456)
at com.vaadin.server.communication.FileUploadHandler.doHandleSimpleMultipartFileUpload(FileUploadHandler.java:403)
at com.vaadin.server.communication.FileUploadHandler.handleRequest(FileUploadHandler.java:285)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.vaadin.server.NoOutputStreamException
at com.vaadin.server.communication.FileUploadHandler.streamToReceiver(FileUploadHandler.java:555)
... 22 more
Are you sure WebContent part is corret in your path? WebContent seem like a eclipse project folder.
What happens if you try without WebContent?
file = new File(basepath + "/WEB-INF/images/" + filename)
HTH
Marco
Hello,
What about creating file before writing into it :
file.createNewFile();
Btw, is this by design that you write onto your webapp dir ?
Regards
WebContent is definitely part of my project folder.
file.createNewFile() produces a java.io.IOException: The system cannot find the path specified.
I am storing the file here temporarily and displaying the uploaded image to the user before storing the image permenantly to a database.
If it is a temporary you can use File.createTempFile(...)
Uploading to a temporary file fails on a java.lang.ArrayIndexOutOfBoundsException : 0
However I can upload directly to the basepath, so i may do this and just delete the file afterwards.
Thank you anyway.
A temp file outside your webapp would be better IMHO.
Best regards
Marco