I have an image that is uploaded and stored on server. I now want to create an Image widget around this URL. My upload method returns the relative path of the image, for example: uploads/image.jpg.
I am trying to generate a URL to let me access this image. This method works in development mode:
String imagePath = uploads/image.jpg;
Image image = new Image(GWT.getHostPageBaseURL() + imagePath.replaceAll('//', '\'));
The replaceAll is used to convert windows file separator to URL separator. This produces an image with URL http://localhost:8080/card-designer/uploads/image.jpg when deployed to my Jetty server. The image does not show.
Is it impossible to create an accessible URL to an image created dynamically? Any help would be much appreciated.
Relative to what ? Where on the disk is your file stored ? This seems like you need to configure jetty. You need to tell jetty that this url corresponds to an image and it should serve it.
See Serving Static Content in the Jetty docs.
Easy solution would be to add something like this in your jetty.xml
You should replace the “resourceBase” parameter with the path to the upload directory on the disk.
Otherwise, create your own servlet that will fetch the images and map it to /upload/ .
I guess it’s working in dev mode because the embedded jetty probably serves unknown urls like static content by default.