diff --git a/articles/tools/collaboration/components/collaboration-avatar-group.adoc b/articles/tools/collaboration/components/collaboration-avatar-group.adoc index 8e2b718841..2e36eb0dc9 100644 --- a/articles/tools/collaboration/components/collaboration-avatar-group.adoc +++ b/articles/tools/collaboration/components/collaboration-avatar-group.adoc @@ -54,16 +54,16 @@ To display an image inside the avatar, you have two options. First, if the image === Images from Backend -The way to load images from a database into components such as `Image` or `Avatar`, is to use `StreamResources`. `CollaborationAvatarGroup` supports stream resources with the `setImageProvider` method. It takes a function that generates `StreamResources` for users based on their `UserInfo`. +The way to load images from a database into components such as `Image` or `Avatar`, is to use a `DownloadHandler`. `CollaborationAvatarGroup` supports download handlers with the `setImageHandler` method. It takes a function that generates a `DownloadHandler` for users based on their `UserInfo`. -For example, if the user entity contains the image as a byte array, you can create a `StreamResource` that loads those bytes and let the framework take care of hosting the image like so: +For example, if the user entity contains the image as a byte array, you can create a `DownloadHandler` that loads those bytes and let the framework take care of hosting the image like so: [source,java] ---- include::{root}/src/main/java/com/vaadin/demo/collaboration/AvatarGroupDocumentation.java[tags=avatar-group-images,indent=0] ---- -Regarding this image provider pattern, `StreamResource` isn't serializable as JSON. As a result, it can't be included in `UserInfo` or sent back and forth through Collaboration Kit. +Regarding this image provider pattern, `DownloadHandler` isn't serializable as JSON. As a result, it can't be included in `UserInfo` or sent back and forth through Collaboration Kit. == Scoping Avatars with Topics @@ -94,7 +94,7 @@ It's a common design pattern to display the user's avatar separately from the ot include::{root}/src/main/java/com/vaadin/demo/collaboration/AvatarGroupDocumentation.java[tags=avatar-group-own,indent=0] ---- -You can set the same `name`, `abbreviation`, and `image` properties as contained in the `UserInfo`. To load the image from a backend, you can pass a `StreamResource` directly to the `Avatar::setImageResource` method. +You can set the same `name`, `abbreviation`, and `image` properties as contained in the `UserInfo`. To load the image from a backend, you can pass a `DownloadHandler` directly to the `Avatar::setImageHandler` method. [discussion-id]`2374106C-8FD4-4AED-B1F3-5045FFF81F55` diff --git a/articles/tools/collaboration/components/collaboration-message-list.adoc b/articles/tools/collaboration/components/collaboration-message-list.adoc index b2d47c8fe2..2dec6a57d4 100644 --- a/articles/tools/collaboration/components/collaboration-message-list.adoc +++ b/articles/tools/collaboration/components/collaboration-message-list.adoc @@ -26,7 +26,7 @@ include::{root}/src/main/java/com/vaadin/demo/collaboration/MessageListDocumenta [NOTE] [classname]`User` and [classname]`UserService` are application-specific example classes. They're not part of the Collaboration Kit API. -The [classname]`CollaborationMessageList` constructor takes two arguments: information about the end user associated with this session; and a topic identifier. The user information is used to render the user name and avatar in the messages submitted by the user. See the <> for more details on how the avatars are rendered, or how to load images from a backend with the [methodname]`setImageProvider()` method. +The [classname]`CollaborationMessageList` constructor takes two arguments: information about the end user associated with this session; and a topic identifier. The user information is used to render the user name and avatar in the messages submitted by the user. See the <> for more details on how the avatars are rendered, or how to load images from a backend with the [methodname]`setImageHandler()` method. The topic identifier works the same as for other Collaboration Kit features. The data in Collaboration Kit is shared among those users who are connected to the same topic. With these components, the topic acts like a chat room. diff --git a/src/main/java/com/vaadin/demo/collaboration/AvatarGroupDocumentation.java b/src/main/java/com/vaadin/demo/collaboration/AvatarGroupDocumentation.java index 7b7c82b7e4..e61ffed661 100644 --- a/src/main/java/com/vaadin/demo/collaboration/AvatarGroupDocumentation.java +++ b/src/main/java/com/vaadin/demo/collaboration/AvatarGroupDocumentation.java @@ -8,7 +8,8 @@ import com.vaadin.demo.domain.User.UserService; import com.vaadin.flow.component.avatar.Avatar; import com.vaadin.flow.component.orderedlayout.VerticalLayout; -import com.vaadin.flow.server.StreamResource; +import com.vaadin.flow.server.streams.DownloadHandler; +import com.vaadin.flow.server.streams.DownloadResponse; /** * Code snippets used in CollaborationAvatarGroup's reference documentation. @@ -41,19 +42,19 @@ public AvatarGroupDocumentation() { // end::avatar-group-own[] } - private void imageProvider() { + private void imageHandler() { // tag::avatar-group-images[] - avatarGroup.setImageProvider(userInfo -> { - StreamResource streamResource = new StreamResource( - "avatar_" + userInfo.getId(), () -> { + avatarGroup.setImageHandler(userInfo -> + DownloadHandler.fromInputStream( + event -> { User userEntity = userService .findById(userInfo.getId()); byte[] imageBytes = userEntity.getImage(); - return new ByteArrayInputStream(imageBytes); - }); - streamResource.setContentType("image/png"); - return streamResource; - }); + return new DownloadResponse(new ByteArrayInputStream(imageBytes), + "avatar_" + userInfo.getId() + ".png", + "image/png", imageBytes.length); + }) + ); // end::avatar-group-images[] }