As StreamResource is depreciated, how to show pdf in filestorage in iframe

now in vaadin StreamResource is depreciated, how can i show pdf stored in filestorage in iframe. My present code is-

if (event.getItem() != null) {
            FileStorage fileStorage = fileStorageLocator.getDefault();
            FileRef document = event.getItem().getFile();
            if (document == null) {
                return;
            }

            try (InputStream inputStream = fileStorage.openStream(document)) {
                ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(inputStream.readAllBytes());
                StreamResource resource = new StreamResource(document.getFileName(), () -> byteArrayInputStream);
                StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
                frame1.setSrc(registration.getResourceUri().toString());
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }

Hi,

According to the StreamResource JavaDoc, the com.vaadin.flow.server.streams.DownloadHandler should be used instead. Take a look at the Vaadin doc for more details.

Regards,
Gleb

Hi Gleb,

How about MemoryBuffer?

image

Use com.vaadin.flow.server.streams.UploadHandler instead?

Regards,
CK

Looks like it. Take a look at the Vaadin doc for more details.

Regards,
Gleb