简体   繁体   中英

Vaadin Upload function

I'm interested in having a button which takes a pic from the user's computer and uploads it on my server.

I managed to solve the server uploading part, but I'm having difficulties in handling the path from the user computer. Vaadin Upload does not provide me full path, but I want it to be dynamic. Looking at the documentation, they use some temp location, but I don't know how to implement that.

public OutputStream receiveUpload(String filename,
                                      String mimeType) {
        // Create upload stream
        FileOutputStream fos = null; // Stream to write to
        try {
            // Open the file for writing.
            file = new File("/tmp/uploads/" + filename);
            fos = new FileOutputStream(file);
        } catch (final java.io.FileNotFoundException e) {
            new Notification("Could not open file<br/>",
                             e.getMessage(),
                             Notification.Type.ERROR_MESSAGE)
                .show(Page.getCurrent());
            return null;
        }
        return fos; // Return the output stream to write to
    }

I'm expecting that when the File Chooser closes, I get some kind of file path or handler so I can put it on my server.

In the filename argument you will have the name of uploaded file. The path of the file however is not sent to the server, this is one of the restrictions of web applications / web browsers.

With the code you use, you will have a copy of the uploaded file on your server in the tmp folder.

There is no way to directly access files on client computers through the web browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM