Vaadin Upload to external resource

I am trying to use the upload dialog but i was wondering what steps need to be taken to make sure the data is not uploaded to the vaadin server but the stream is redirected to an external resource for which an API is available.

Do i need to make a public class iRODSReceiver implements Receiver { and is there an example of how this should look like?

Yes, a Receiver is what you need

Look at the existing Receivers for inspiration?

I have made a copy of

public class MultiFileBuffer extends AbstractFileBuffer
        implements MultiFileReceiver {

and placed breakpoints at every function but it will only trigger

 public OutputStream receiveUpload(String fileName, String mimeType) {
     System.err.println("receiveUpload: " + fileName + " " + mimeType);

once the upload to the vaadin application is finished. Which method should or shoud i? override to start a function once the stream has received so i can “hijack” its destination?

This might help ? https://vaadin.com/docs/latest/advanced/stream-resources have to check how to implement it if it is the right one…

Hmm this looks interesting https://stackoverflow.com/questions/75165362/vaadin-flow-upload-component-streaming-upload


    @Override
    public OutputStream receiveUpload(String filename, String mimeType) {
        try {
            // Define the path where the file will be saved
            File file = new File("path/to/save/" + filename);
            return new FileOutputStream(file);
        } catch (Exception e) {
            // Handle exceptions appropriately
            e.printStackTrace();
            return null;
        }
    }
}```

but then again it only calls this function once the file is uploaded to the vaadin instance hmm

so almost there but not there yet

            MyReceiver myReceiver = new MyReceiver();
            Upload upload = new Upload(myReceiver);

I’m slighlty confused, so a question :slightly_smiling_face: Are you trying to push the stream of the bytes coming from the uploaded file to a service/API in your application server where your Vaadin app is running OR would you like the browser to submit the files to a totally different URL/server?

If your API is in the same JVM as your Vaadin code, check this blog post and helpers in Viritin. Oldie, but goldie :sunglasses: Uploads and downloads, inputs and outputs | Vaadin

I am trying to push the stream directly to a remote resource as it could be a fair few gigabytes people would like to upload

and it would be a waste to first store it on a vaadin instance (with minimal storage space) and then push it to the resource (this also will take twice as long)

would you like the browser to submit the files to a totally different URL/server?

that one, but it uses a different API so it needs a InputStream to write to it

This is what i use to sent it to the remote instance (after it is sent to the server first)

IOUtils.copy(buffer.getInputStream(), irodsFileOutputStream);

but i would like to submit this stream immediatly

Checing it out! :slightly_smiling_face:

This…

In the streaming solution, we turn the setup upside down, again, and this way we get more optimal API for dynamic purposes. We pipe one stream to another and provide the piped version forward.

might be it?

Hmm I am using the pure java implementation so i guess Flow Viritin is not available? Also https://github.com/viritin/flow-viritin/blob/master/src/main/java/org/vaadin/firitin/components/UploadFileHandler.java is a 404 ?

ow wait thats a Directory plugin :smile: that… you made