flet
flet copied to clipboard
bug - flet caches local image loads
With image container dev can set the src property to load in a new image. This image can be remote or local . I have found with local loads of pngs, Flet go server will not send back latest file. I discovered this writing a tool that converts svg code to a png file and saving it locally everytime the svg code changed a new png is generated but saved with same file name (output.png) When flet code tries to image.src = output.png the same image is returned.
you can view this behaviour in this code
https://github.com/hololeo/flet-hacks/blob/main/flet_svg_tool.py (change to below)
png = Image (
src = img_file_path
#src_base64 = b64_string
)
The work around is to convert the png to base64 then pass it to flet. But this produces a new side effect - the image flickers (probably a flutter bug)
I suspect this is happening due to caching in fletd. perhaps in the http headers
https://imagekit.io/blog/ultimate-guide-to-http-caching-for-static-assets/
...but, have you tried appending something to an image URL on Flet side, to force its reload, like:
Image(src=f"output.png?ts={time.time()}")
Is it still actual?
Image(src=f"output.png?ts={time.time()}")
What is the role of the ?ts=
here please ?
It could be anything with a random value. That's a usual trick on the web to make client believe it's a new resource.
I see. Any Link or resource please? I want to learn more.
Just googled: https://www.uptrends.com/support/kb/monitor-settings/random-url-value-cache-busting
Thanks. 👍🏾
Closing the issue? ;)
i think this is still open as reported here:
The workaround suggested by @hololeo on Discord
another work around may be to use an http path to the local image and use 'cache buster' to the tail of that url string i think the fix is in setting a cache expire header on the go server (or something like that)
doesn't work. Perhaps I'm doing something wrong, but
img.src = "file:///Volumes/SSD/Data/Devel/proj1/assets/preview.png?{random.randint(0, 1000)}"
fails to load images at all. My browser loads the images above OK.
instead of file:/// use https://wahteveryourhost:yourport that flet server launches with use the debug to see the address
import logging
logging.basicConfig(level=logging.DEBUG)