C++ example for cache system to send file - 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: C++ example for cache system to send file (/thread-2530.html) |
C++ example for cache system to send file - Gav75va - 10-14-2021 Hello there I need to update some old code. It currently generates a PDF file and saves it to the UserCacheDir and then uses SendFile to download the file for the user. The above no longer works in an ISAPI release build, after some research I've found that the cache system is what should be used now for this. I've been unable to locate a C++ example of using the cache system to send a file. Any help appreciated Thanks Gav RE: C++ example for cache system to send file - Alexandre Machado - 10-18-2021 Please check this new demo: https://github.com/Atozed/IntraWeb/tree/master/15/C%2B%2B/Cache/OneTimeCache It is the same project named OneTimeCache from Delphi demo repository, converted to C++ Builder. It should get you familiarized with the new Cache feature and how to get started. Please let me know if you have any other questions. RE: C++ example for cache system to send file - Gav75va - 11-05-2021 Hello there Thank you for the example code. I've had it working using the server build. So I switched over to my ISAPI project where it also worked in debug mode. However, when I do a release build, the file doesn't get served - It appears that the path I'm using doesn't exist, so please advise which In debug inside builder, when I create my PDF file this is the location... C:\Users\icaru\AppData\Local\Temp\01d2hlems0\user\TQpucrrKel5-GK9lReBKX05yXdq In release outside of Builder, when I create my PDF file this is the location... C:\WINDOWS\TEMP\01d2hlyb7v\user\wbKedcHYwhsQH4blNu6GiBdRJaa I added a directory exists check and in debug this passes, but in release it doesn't. What should I be using in release mode? Here's my example code... // Path for generated file and file name for the file AnsiString sPath = WebApplication->UserCacheDir; AnsiString sPathFile = sPath + String("contents.pdf"); // test message for release build testing, confirm generated file location WebApplication->ShowMessage(sPath); // test message for release build testing, check directory WebApplication->ShowMessage("directory exist check"); if (System::Sysutils:irectoryExists(sPath)) WebApplication->ShowMessage("directory exists"); else WebApplication->ShowMessage("directory does NOT exist") // Object for creating the PDF file TContentsScreenPDF* oPDFIt = new TContentsScreenPDF(NULL, oSession->oSys, oSession->oDM, oContentsList); // test message for release build testing WebApplication->ShowMessage("generate PDF"); // Generate PDF if (oPDFIt->Export(sPathFile.c_str(), "Contents Report")) { // test message, confirm generate worked WebApplication->ShowMessage("PDF created"); // PDF generated, copy it to cache String sTempFileName = TIWAppCache::NewTempFileName(); String sFileUrl = oSession->WebApplication->CacheFiles->Add(sFileName); FileCopy(sPathFile, sTempFileName, true); String sURL = TIWAppCache::AddFileToCache(this, sTempFileName, TIWMimeTypes::GetAsString(mtPDF), ctOneTime); // Serve up the file WebApplication->NewWindow(sURL); } RE: C++ example for cache system to send file - Jose Nilton Pace - 11-05-2021 Hi, try something like this: Code: // get a new temp file name. This method only returns a file name, the file is not created RE: C++ example for cache system to send file - Gav75va - 11-05-2021 Hi Jose Sorry, somehow I posted my reply above before actually finishing what I was putting together. I thought I'd tried what you shared, but guess I missed something off and went off down the rabbit hole. That appears to work, so I'll test with other reports. Thanks for your help |