Flow Upload Component Issues.

I must have missed something with the new Flow Java Upload component. I simply cannot seem to get a file saved to the server-side. I tried instantiating the Upload component with a FileBuffer, and when the upload play button is clicked the file information (name, size, mime-type) is all available, but the input stream is unaccessible. I get the following exception:

java.io.IOException: Access is denied

Here’s what I am trying in the SucceededListener:

byte[] os = new byte[(int)event.getContentLength()]
;
buffer.getInputStream().read(os);

That is where the exception gets tossed.

Any suggestions would be greatly appreciated. And I can add more of the code if needed. Am I in the proper listener? I just had that thought, should I be using the FinishedListener instead, would that even make a difference?

Thank you.

Hi Steven,

from the error you get I would expect that the file the FileBuffer created cannot be read. But I do not know why. Have you specified any special file factory? By default FileBuffer uses File.createTempFile().

You can also try MemoryBuffer to limit the possible error causes.

Cheers

Paul,

I tried the MultiFileMemoryBuffer, and that worked to save the file off to a specified directory. Here is the snippet of the Upload addSucceededListener event. Thanks for your suggestion about trying the memory buffer.

upload.addSucceededListener(event -> {
            try {
                byte[] buf = new byte[(int)event.getContentLength()]
;
                InputStream is = buffer.getInputStream(event.getFileName());
                is.read(buf);
                File targetFile = new File("c:/Temp/"+event.getFileName());
                OutputStream outStream = new FileOutputStream(targetFile);
                outStream.write(buf);
                System.out.println("Finished " + event.getFileName() +" upload!");
                outStream.flush();
                outStream.close();
            } catch (IOException ex) {
                Logger.getLogger(UploadView.class.getName()).log(Level.SEVERE, null, ex);
            }
        });

I’m glad I could help!