AsyncImage : reload image from webserver

422 views
Skip to first unread message

JF

unread,
Apr 6, 2013, 6:40:54 AM4/6/13
to kivy-...@googlegroups.com
Hi!

I'm trying to display an image coming from a webserver (http://xxx.xxx.xxx.xxx/image.jpg).
This image is regularly updated by the webserver.

In my Kivy application, I created a "AsyncImage" widget, and I'm trying to update the image that is displayed. 

I've tried so far:
self.imageWidget.reload()
#or
self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg'
#or
self.image.source = 'dummyFileOnLocalFileSystem.jpg'
self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg'

But none of them seems to work. I tried to set the property nocache to True, with no result.
The 2 first commands seem to do...nothing, and the last one would reload the same picture, even if it has changed on the server (it's reloading from cache, I suppose).

Is there a way to force the AsyncImage widget to reload the image file from the remote server?

Thanks!

Gabriel Pettier

unread,
Apr 6, 2013, 7:42:54 AM4/6/13
to kivy-...@googlegroups.com
Hi

There is always the common trick of using

from uuid import uuid4

self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg?%s' % uuid4().hex

this will get you a different url each time, avoiding the cache issue.

not exactly beautiful, i know, but if you are in a hurry…

cheers
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Jean-François Milants

unread,
Apr 6, 2013, 8:15:11 AM4/6/13
to kivy-...@googlegroups.com
That could be a good workaround but... it doesn't work :/

If a set source with the simple URL:

But if I add anything to the URL, it does't work:

Traceback:
[DEBUG             ] [ImagePygame ] Load <Images/Player-Next.png>
[ERROR             ] [Failed to load image <http]//192.168.0.14:9000/music/current/cover.jpg?409e5de17b94471fb2f2b310047e9a2f>
Traceback (most recent call last):
  File "C:\Kivy-1.5.1-w32\kivy\kivy\loader.py", line 166, in _load_urllib
    prefix='kivyloader', suffix=suffix)
  File "C:\Kivy-1.5.1-w32\Python\lib\tempfile.py", line 300, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags)
  File "C:\Kivy-1.5.1-w32\Python\lib\tempfile.py", line 235, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 22] Invalid argument: 'c:\\users\\jf\\appdata\\local\\temp\\kivyloadersd_1oo.jpg?409e5de17b94471fb2f2b310047e9a2f'

Copy/Pasting these URL in Chrome just work fine...

Did I miss something?

Jean-François Milants


2013/4/6 Gabriel Pettier <gabriel...@gmail.com>
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/YJct8GHetjo/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Mathieu Virbel

unread,
Apr 6, 2013, 8:45:22 AM4/6/13
to kivy-...@googlegroups.com
The loader use the extension to determine what kind of file you get.
So the end of the url should be an extension.

So the gabriel's trick will not work obviously.

If you use nocache=True in the AsyncImage(), try to use the reload()
method. Setting to the same source will not trigger anything.

Regards,

Mathieu
Le 06/04/2013 14:15, Jean-Fran�ois Milants a �crit :
> Jean-Fran�ois Milants
>
>
> 2013/4/6 Gabriel Pettier <gabriel...@gmail.com
> <mailto:gabriel...@gmail.com>>
>
> Hi
>
> There is always the common trick of using
>
> from uuid import uuid4
>
> self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg?%s' % uuid4().hex
>
> this will get you a different url each time, avoiding the cache issue.
>
> not exactly beautiful, i know, but if you are in a hurry�
> <mailto:kivy-users%2Bunsu...@googlegroups.com>.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/YJct8GHetjo/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users%2Bunsu...@googlegroups.com>.

Jean-François Milants

unread,
Apr 6, 2013, 9:32:46 AM4/6/13
to kivy-...@googlegroups.com
Hi,

I tried setting nocache to true, and call reload() on the AsyncImage object, but it doesn't seem to do anything.

The AsyncImage object is declared in a .kv file, and the reload method is called in a callback method from a Clock in the python code. I don't know if these details are important or not in this issue.

Thanks for your help!

Jean-François Milants


2013/4/6 Mathieu Virbel <txp...@gmail.com>
The loader use the extension to determine what kind of file you get.
So the end of the url should be an extension.

So the gabriel's trick will not work obviously.

If you use nocache=True in the AsyncImage(), try to use the reload()
method. Setting to the same source will not trigger anything.

Regards,

Mathieu
> Jean-François Milants
>
>
> 2013/4/6 Gabriel Pettier <gabriel...@gmail.com
> <mailto:gabriel...@gmail.com>>
>
>     Hi
>
>     There is always the common trick of using
>
>     from uuid import uuid4
>
>     self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg?%s' % uuid4().hex
>
>     this will get you a different url each time, avoiding the cache issue.
>
>     not exactly beautiful, i know, but if you are in a hurry…
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Thomas Hansen

unread,
Apr 6, 2013, 11:14:24 AM4/6/13
to kivy-...@googlegroups.com
You can always use the trick on the trick ;)



On Saturday, April 6, 2013, Mathieu Virbel wrote:
The loader use the extension to determine what kind of file you get.
So the end of the url should be an extension.

So the gabriel's trick will not work obviously.

If you use nocache=True in the AsyncImage(), try to use the reload()
method. Setting to the same source will not trigger anything.

Regards,

Mathieu
> Jean-François Milants

>
>
> 2013/4/6 Gabriel Pettier <gabriel...@gmail.com
> <mailto:gabriel...@gmail.com>>
>
>     Hi
>
>     There is always the common trick of using
>
>     from uuid import uuid4
>
>     self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg?%s' % uuid4().hex
>
>     this will get you a different url each time, avoiding the cache issue.
>
>     not exactly beautiful, i know, but if you are in a hurry…

Thomas Hansen

unread,
Apr 6, 2013, 11:16:04 AM4/6/13
to kivy-...@googlegroups.com
But maybe we should also check the mime type / content type on http responses notepad of relying just on extension?

Gabriel Pettier

unread,
Apr 6, 2013, 1:48:19 PM4/6/13
to kivy-...@googlegroups.com
Oh well, the trick can be slightly modified so it ends in .jpg anyway.

self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg?%s.jpg' % uuid4().hex

Of course, it would be better to have the nocache=True + reload to work.

regards

On Sat, Apr 06, 2013 at 02:45:22PM +0200, Mathieu Virbel wrote:
> The loader use the extension to determine what kind of file you get.
> So the end of the url should be an extension.
>
> So the gabriel's trick will not work obviously.
>
> If you use nocache=True in the AsyncImage(), try to use the reload()
> method. Setting to the same source will not trigger anything.
>
> Regards,
>
> Mathieu
> > Jean-François Milants
> >
> >
> > 2013/4/6 Gabriel Pettier <gabriel...@gmail.com
> > <mailto:gabriel...@gmail.com>>
> >
> > Hi
> >
> > There is always the common trick of using
> >
> > from uuid import uuid4
> >
> > self.image.source = 'http://xxx.xxx.xxx.xxx/image.jpg?%s' % uuid4().hex
> >
> > this will get you a different url each time, avoiding the cache issue.
> >
> > not exactly beautiful, i know, but if you are in a hurry…

Jean-François Milants

unread,
Apr 7, 2013, 4:06:29 AM4/7/13
to kivy-...@googlegroups.com
Oh thanks! The trick on the trick seems to work... It seems to be a workaroung, thought...

I'll have a look in the code and try to understand why reload() doesn't work. Thanks for your help!

Jean-François Milants


2013/4/6 Gabriel Pettier <gabriel...@gmail.com>
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages