Boring "URLDownloadToFile_" problem

Just starting out? Need help? Post your questions and find answers here.
User avatar
pb-user
User
User
Posts: 10
Joined: Tue Mar 02, 2010 6:36 pm

Boring "URLDownloadToFile_" problem

Post by pb-user »

Hi folks,

since several days I'm struggling with a problem downloading an webcam image from www.
Yes, I know. Sounds very simple. But please let me explain.

First I used the PB internal procedure "ReceiveHTTPFile()" but it fails. Than I started with " URLDownloadToFile_".
I works partly. I would like to update the webcam image every 5 minutes. The downloaded file is
stored in windows temp folder and then a ImageGadget is updated.

The problem now is, that it looks like, that "DeleteUrlCacheEntry_" does not clear the cache. On first start of
the procedure everthing works fine, after 5 minutes update the image is not updated. What for me is
strange, on every new start of the code the image is updated (close in compiler/exe and restart)

I also tried to delete the temp file before the download starts, but nothing helps :cry:
The webcam image on site is password protected and I handed over it in the url$ by "xxx:yyy@"

Is there any chance to empty the cache or is there another solution? At the moment I run out of ideas. I already had coded this years ago with "MMB - Multimedia Builder" and it works perfect. This software is now outdated that's why I try to port this to PB.

I will not handover the user the passwords for the webcam, so I think a WebGadget is also not a solution.

In principle is very simple the software should download the image and show it in a window. I use Win 7 and XP in 32 and 64bit. Same problem on both systems.

Hopefully one of the forums pb-experts can help me to get this fixed.

Code: Select all


cam$=Temp$+"cam_temp.jpg"
url$="http\\xxx:yyy@www.test-url.com

Procedure Loadpicture(url$,cam$)
  DeleteUrlCacheEntry_(url$)
  URLDownloadToFile_(0,url$,cam$,0,0) 
  LoadImage(#Background, )
 
  If IsGadget(#background)
    SetGadgetState(#background,ImageID(#background)) 
  EndIf 

EndProcedure
Pb-User

Windows 7 - 64bit - PureBasic 4.51
User avatar
Kiffi
Addict
Addict
Posts: 1487
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Boring "URLDownloadToFile_" problem

Post by Kiffi »

try to append a random parameter to your URL to bypass the cache

Code: Select all

URL$ = "http://yoursite.com/index.php?dummy=" + Str(ElapsedMilliseconds())
Greetings ... Kiffi
Hygge
User avatar
pb-user
User
User
Posts: 10
Joined: Tue Mar 02, 2010 6:36 pm

Re: Boring "URLDownloadToFile_" problem

Post by pb-user »

Kiffi,
thx for reply. But I do not clearly understand what to do.

I have a webcam image on a server "http://yoursite.com/webcam/image.jpg" to download.
How to handle this random parameter to bypass the cache? :?

regards
Pb-User

Windows 7 - 64bit - PureBasic 4.51
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Boring "URLDownloadToFile_" problem

Post by DarkDragon »

pb-user wrote:Kiffi,
thx for reply. But I do not clearly understand what to do.

I have a webcam image on a server "http://yoursite.com/webcam/image.jpg" to download.
How to handle this random parameter to bypass the cache? :?

regards
You don't need to handle it, just append it like he described (jpg instead of php should work). The UrlDownloadToFile will think its a completely new page.
bye,
Daniel
User avatar
pb-user
User
User
Posts: 10
Joined: Tue Mar 02, 2010 6:36 pm

Re: Boring "URLDownloadToFile_" problem solved

Post by pb-user »

Yeah, I got it. Now work's perfect. Thanks for help :lol:
I used it like that:

Code: Select all

url$="http://yoursite.com/webcam/image.jpg?dummy="+ Str(ElapsedMilliseconds())
and the cache problem is solved.

Only for my understanding, for what is this "?dummy" in the IE used?
Pb-User

Windows 7 - 64bit - PureBasic 4.51
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Re: Boring "URLDownloadToFile_" problem

Post by Sirius-2337 »

Only for my understanding, for what is this "?dummy" in the IE used?
"dummy" is an additional parameter that you send with your Request. "dummy" is not used by the IE its just a dummy. You could use any other word instead.
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: Boring "URLDownloadToFile_" problem

Post by RichAlgeni »

The question mark, '?' is a delimiter. The 'dummy=' is a parameter. By adding '?dummy=' + Str(ElapsedMilliseconds()), you are making a unique request each time, since ElapsedMilliseconds() increments over time. If your request is not unique, the url download function will look for data in the cache, rather than send the request to the server.

You are, in a sense, tricking the system into requesting data from the server for each call.
Post Reply