Accessing uploaded file contents

Is it possible to use a fileUploader and read the contents back afterwards? For example:

    @Subscribe("importField")
    public void onFileFieldFileUploadSucceed(SingleFileUploadField.FileUploadSucceedEvent event) {
        File file = temporaryStorage.getFile(importField.getFileId());
        if (file != null) {
            FileRef fileRef = temporaryStorage.putFileIntoStorage(importField.getFileId(), event.getFileName());
            importField.setValue(fileRef);
            System.out.println(fileRef);
            System.out.println(fileRef.getPath());

            List<List<String>> records = new ArrayList<>();
            try (BufferedReader br = new BufferedReader(new FileReader(fileRef.getFileName()))) {
                String line;
                while ((line = br.readLine()) != null) {
                    String[] values = line.split(",");
                    records.add(Arrays.asList(values));
                }
                System.out.print(records);
            } catch (IOException e) {
                System.out.println(e);
            }
        }
    }

Unfortunately the file can’t be read this way (IOException).

java.io.FileNotFoundException: fs:\2023\03\14\870f3a05-df67-f209-fa01-d3616c59e230.csv?name=Simpro_upload_13122022.csv (The filename, directory name, or volume label syntax is incorrect)

Hi
may be this help:

public void onFileFieldFileUploadSucceed(SingleFileUploadField.FileUploadSucceedEvent event) {
    InputStream file = ((FileUploadField) event.getSource()).getFileContent();
...
1 Like

Ah it’s an InputStream! Thank you, that’s exactly what I want.