dcrudo
asked on
URLDownlloadToFile How to clear Cache First?
Dear experts,
I'm using the 'URLDownloadToFile' to download a file...and it works fine...the issue is that I use it to download a binary
update from a webserver ...but if I don't clear the cache first...the file is not downloaded frome the server and is taken
from the cache...
is there a way to delete that file from the cache first, and then download it? Or to force a download even if the file is
in the cache?
Thank you!
Dave
I'm using the 'URLDownloadToFile' to download a file...and it works fine...the issue is that I use it to download a binary
update from a webserver ...but if I don't clear the cache first...the file is not downloaded frome the server and is taken
from the cache...
is there a way to delete that file from the cache first, and then download it? Or to force a download even if the file is
in the cache?
Thank you!
Dave
The flags I am posting do not work with UrlDownloadToFile (router trace shows no difference), but in using UrlDownloadToCacheFile they do work (since v4.01 sp2 of Internet explorer). By passing the flag BINDF_GETNEWESTVERSION you can force the url handling to recheck the site for a newer version, vs reading the data from the cache. More info can be obtained here:
http://support.microsoft.com/kb/q196466/
Below is an example of using the URLDownloadToCacheFile function. The only real difference is that the function gives you the file name instead of you specifying one. (But you could always use CopyFile to move it.). And because you get back the cache file name, you can delete it using DeleteFile, etc if you wanted.
Regards,
Russell
const
BINDF_ASYNCHRONOUS = $00000001;
BINDF_ASYNCSTORAGE = $00000002;
BINDF_NOPROGRESSIVERENDERI
BINDF_OFFLINEOPERATION = $00000008;
BINDF_GETNEWESTVERSION = $00000010;
BINDF_NOWRITECACHE = $00000020;
BINDF_NEEDFILE = $00000040;
BINDF_PULLDATA = $00000080;
BINDF_IGNORESECURITYPROBLE
BINDF_RESYNCHRONIZE = $00000200;
BINDF_HYPERLINK = $00000400;
BINDF_NO_UI = $00000800;
BINDF_SILENTOPERATION = $00001000;
BINDF_PRAGMA_NO_CACHE = $00002000;
BINDF_GETCLASSOBJECT = $00004000;
BINDF_RESERVED_1 = $00008000;
BINDF_FREE_THREADED = $00010000;
BINDF_DIRECT_READ = $00020000;
BINDF_FORMS_SUBMIT = $00040000;
BINDF_GETFROMCACHE_IF_NET_
BINDF_FROMURLMON = $00100000;
BINDF_FWD_BACK = $00200000;
BINDF_PREFERDEFAULTHANDLER
BINDF_RESERVED_3 = $00800000;
procedure TForm1.Button2Click(Sender
var dwMark: LongWord;
bSuccess: Boolean;
lpszFile: Array [0..MAX_PATH] of Char;
begin
dwMark:=GetTickCount;
try
// With this version, the file will get pulled from cache
// bSuccess:=(URLDownloadToCa
//
// This version re-checks the site for a newer version
bSuccess:=(URLDownloadToCa
finally
dwMark:=GetTickCount-dwMar
end;
ShowMessage(Format('Downlo
if bSuccess then
ShowMessage(Format('Your bits are located in the following file: %s', [lpszFile]));
end;
ASKER
Hello,
I've tried to use the following:
URLDownloadToFile(nil,
'http://www.mysite.com/updates/program.exe',
Pchar(ExtractFilePath(appl ication.Ex ename)+'pr ogram.exe' ),
BINDF_GETNEWESTVERSION , bsc);
should not give the same result?
But the file is not downloaded again :(
any idea?
I've tried to use the following:
URLDownloadToFile(nil,
'http://www.mysite.com/updates/program.exe',
Pchar(ExtractFilePath(appl
BINDF_GETNEWESTVERSION , bsc);
should not give the same result?
But the file is not downloaded again :(
any idea?
ASKER
Hi Ivanov,
but then how do I push the file back to the client? ...
Thx!
Dave
but then how do I push the file back to the client? ...
Thx!
Dave
For example like this:
<?php
header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
header('Pragma: no-cache'); //HTTP/1.0
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Dispositio n: attachment; filename="downloaded.pdf"' );
// The PDF source is in original.pdf
readfile('original.pdf');
?>
<?php
header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
header('Pragma: no-cache'); //HTTP/1.0
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Dispositio
// The PDF source is in original.pdf
readfile('original.pdf');
?>
What part of this:
>> The flags I am posting do not work with UrlDownloadToFile (router trace shows no difference), but in using UrlDownloadToCacheFile they do work (since v4.01 sp2 of Internet explorer).
did you not understand? Let me rephrase it; you MUST use UrlDownloadToCacheFile because the flags DO NOT WORK with UrlDownloadToFile
Russell
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works! Thank you!
<?php
header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
header('Pragma: no-cache'); //HTTP/1.0
?>
This should force the download from the server and skip the cache.