Reputation: 25
I get my images from my database via the StreamResource and use afterwards the Image() class to show the picture. Is it possible to get from this StreamResource or Image class the URL? Through the browser I can find out that the image has the URL that looks like: "... / Web/APP/connector/0/32/source/Picture-xxx.JPG"
I need the URL to the image for CSSInject.
Thanks in advance
Upvotes: 1
Views: 3026
Reputation: 2605
This is a typical use case for creating a request handler: As mentioned in the provided link: Request handlers are useful for catching request parameters or generating dynamic content, such as HTML, images, PDF, or other content.
Upvotes: 0
Reputation: 26
So..
Client side Vaadin resource link pattern is like:
[protocol]+"://"+[currentUrl]+"/APP/connector/"+[uiId]+"/"+[cid]+"/source/"+[filename]
where:
protocol - request protocol,
currentUrl - current URL,
uiId - Vaadin UI identifier,
cid - connector identifier,
filename - filename.
Example function to get url:
String getResourceURL(AbstractClientConnector connector,FileResource resource){
String protocol = UI.getCurrent().getPage().getLocation().getScheme();
String currentUrl = UI.getCurrent().getPage().getLocation().getAuthority();
String cid = connector.getConnectorId();
Integer uiId = connector.getUI().getUIId();
String filename = resource.getFilename();
return protocol+"://"+currentUrl+"/APP/connector/"+uiId+"/"+cid+"/source/"+filename;
}
where:
connector is for example Image object
resource is FileResource
Upvotes: 1