Upload problem.

I have serious problem with Upload component. Something very strange is happening.

I upload file into bytearrayoutputstream. It works. On separate button I process this text. It works.

But then I implemented uploadSucceeded and I just call the same logic as on that separate button.

The logic goes through without problem, but then vaadin just hangs. I tried to debug, I got out of my logic to java.lang.reflect.Method.

What to do???

THanks and BR

Can someone show example how to upload to byte and on finished print everything to System.out?

:slight_smile:

Here is a quick “cut” from one of my working projects. I changed file to ByteArrayOutputStream as you asked, so take this as an example.

Note, that I quickly changed it in a text editor, so mispells could be present here, but in general this shows how to work with a file uploader. No matter, want you upload into a file or byte array - you simply create an appropriate output stream object and return it to uploader when asked - it will do the rest.


public class UploadTest extends VerticalLayout implements Receiver, Upload.SucceededListener
{

    private Upload uploader = new Upload ( "Upload document", this );
    ByteArrayOutputStream tmpFile = null;

    public IrbisView ()
    {
        super ();
        setMargin ( false );
        setSpacing ( true );
        uploader.addListener ( ( Upload.SucceededListener ) this );
    }

    public OutputStream receiveUpload ( String filename, String MIMEType )
    {
        try
        {
            tmpFile = new ByteArrayOutputStream();
            return tmpFile;
        }
        catch ( IOException ex )
        {
            ex.printStackTrace ();
            throw new RuntimeException ( ex );
        }
    }

    public void uploadSucceeded ( SucceededEvent event )
    {
        if ( tmpFile != null)
        {
        	System.out.println ( tmpFile.toByteArray() );
       	}
    }

}