Atozed Forums

Full Version: TIWURLWindow question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm using the TIWURLWindow-control to show the contents of a PDF file with following code found in your examples
Code:
procedure TfrmMain.SendPdfStreamToURLWindow(const aPDFFile, aUserFilename: string);
var
  xURL: string;
  xFileStream: TFileStream;
begin
  uwAnteprima.URI := '';
  xFileStream := TFileStream.Create(aPDFFile, fmOpenRead);
  try
    xURL := TIWAppCache.StreamToCacheFile(Self, xFileStream, TIWMimeTypes.GetAsString(mtPDF), ctOneTime);
    uwAnteprima.URI := xURL;
  finally
    xFileStream.Free;
  end;
end;
All works fine. Now the pdf-viewer (f.e. in Edge or Chrome) has a "download"-button. Clicking it, the browser shows a "cryptic" name. Is there a way to force the cache-filename with the name of my choice (original name or somewhat stored in my underlying database)?
thanks and best regards
Toni Santa
Hi Tony, Yes, take a look at the end of StreamToCacheFile:
Code:
xURL := TIWAppCache.StreamToCacheFile(Self, xFileStream, TIWMimeTypes.GetAsString(mtPDF), ctOneTime, 'YourFileName.pdf');
Hi Jose, adding this parameter with the filename I receive an error "cannot open file" with temporary-session-path and filename. The contents is loaded from a streamfile with guid-name, so I do not have a real file with this filename. I'm using IW 15.1.0 with Delphi 10.3.1;
Hi Tony, Do a simple test, change Self by aSession

TIWAppCache.StreamToCacheFile( Self, ...
by
TIWAppCache.StreamToCacheFile( aSession, ...