Atozed Forums
Refreshing TIWBSImage - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Refreshing TIWBSImage (/thread-1305.html)



Refreshing TIWBSImage - pdinsd - 10-10-2019

I have a TIWBSImage on a form.  I then use the TIWFileUploader to upload a new logo.  However, I notice that the TIWBSImage does not update with the new image unless I completely close the browser (close the session) and re-open it.  The reason is that the form is pulling the image from the IW cache, instead of the relative URL file path I've set in the TIWBSImage property as shown below:

This code works when the form loads:

Code:
    CurDir := TIWAppInfo.GetAppPath;
    logodir:='/iwbs/images/';
    logostr:=Curdir+'wwwroot/iwbs/images/'+tenant+'logo.png';
    if (fileexists(logostr)) then
    begin
      currentLogo.ImageFile:=logodir+tenant+'logo.png';
      tenantTabOptionsPage3.Repaint;
    end;

But after this point, the image always loads from the cache (which is different URL than the coded URL).  So uploading a new image has no effect until the session is restarted.

How can I always pull the image from the ImageFile property instead of the cache?


RE: Refreshing TIWBSImage - kudzu - 10-10-2019

There are several approaches to this. The first is most likely the easiest.

-Use FilesNC reference.
https://www.atozed.com/2010/01/20100503a-en/

-Rename the image so it has a new URL and update the reference in the image.

-Use a content handler and disable caching

-Use a TImage instead of a file based image.


RE: Refreshing TIWBSImage - Jose Nilton Pace - 10-11-2019

Hi, try to use IW Cache System:
Code:
procedure TIWForm5.IWGradButton2Click(Sender: TObject);
var
  xFileName: string;
  xURL: string;
begin
  // get a new temp file name. This method only returns a file name, the file  is not created
  xFileName := TIWAppCache.NewTempFileName;
  // copy a sample image file to our new cache file. We are just simulating a dynamic image file creation
  FileCopy(TIWAppInfo.GetAppPath + 'web1.jpg', xFileName, True);
  // add the image file to the cache. cache type is defined as ctOneTime, i.e., the file will be deleted when served
  xURL := TIWAppCache.AddFileToCache(Self, xFileName, TIWMimeTypes.GetAsString(mtJPG), ctOneTime);
  // open a new window with our image file
  WebApplication.NewWindow(xURL);
end;

Code:
var
  xFileName: string;
  xURL: string;
begin
  CurDir := TIWAppInfo.GetAppPath;
  logostr:=Curdir+'wwwroot/iwbs/images/'+tenant+'logo.png';
  if (fileexists(logostr)) then
  begin
      // get a new temp file name. This method only returns a file name, the file  is not created
      xFileName := TIWAppCache.NewTempFileName;
      // copy your image file to our new cache file. We are just simulating a dynamic image file creation
      FileCopy(logostr, xFileName, True);
      // add the image file to the cache. cache type is defined as ctOneTime, i.e., the file will be deleted when served
      xURL := TIWAppCache.AddFileToCache(Self, xFileName, TIWMimeTypes.GetAsString(mtJPG), ctOneTime);
      currentLogo.ImageFile:=xURL;
      tenantTabOptionsPage3.Repaint;
  end;
From here: https://github.com/Atozed/IntraWeb/blob/master/XIV/Delphi/Working%20with%20Cache/OneTimeCache/Unit5.pas