I’m a Vaadin newbie. I’m wondering what the recommendend way of handling images is.
I was using the upload component to change a user’s avatar and had initially used a Label with XHTML. But this didn’t refresh the image when it changed, I assume because the name of the file hadn’t changed, even though its contents had. I then switched to using Embedded and a FileResource, which works fine.
My question is whether there are any advantages or disadvantages to using an Embedded vs. a Label. Are there any particular costs or overhead in Embedded? And, in general, which one is it preferable to use for images?
I guess
Embedded is the way to go, as that is the main supported way of adding pictures in Vaadin applications. I don’t think there is any big overhead, and the client side should be quite simple. You can check what it actually does with Firefox firebug / Crome inspector / IE Developer Tools. I think Embedded is a little bit more robust as you have the possibilty to use Resource on the server side.
Thanks! I’ll look at the client-side output, as you suggest.
I continued investigating and there seems to be difficulty handling new files that have the same name as old files. In my case, the user’s avatar’s file name is simply .png, so its name doesn’t change when the user uploads a new one.
Vaadin was confused by this and showed older versions of the images! Bizarrely, even after I restarted the server, and with no picture on disk whatsoever, I continued getting old versions. I say versions because it would alternate between two previously uploaded images.
When the filename changes (by appending a timestamp), Vaadin handles it correctly. Is this the expected behaviour?
Problem is with browser cache. You get previous image because browser has cached that file with that name, To use one name, you should specify cache expiration.
Thanks for pointing that out. I re-read the section on Embedded and saw the discussion of cache expiration, which I seem to have missed the first time around. I think I’ll go with unique file naming, because I actually do want browser caching
Hi all,
Embedded can not support (actually not recognize) those file types like : *.JPG, *.PNG…
but for small letter tails its ok.
Any idea to fix this problem?
I am using vaadin 8.2, but still that error exists. I am unable to upload any image with upper case extension like : *.JPG, *.PNG, error is “File isn’t a supported type: file_name.JPG”. Any solution for this issue?