Blog Options
Archive
<< April 2024 >>-
Monday 22
- Easy Guide to Building a Pexels Gallery App with TMS WEB Core -
Wednesday 17
- New free component for sophisticated file uploads with TMS WEB Core -
Tuesday 16
- Closing the gap with TMS FNC UI Pack new additions -
Thursday 11
- Unveiling the Latest Enhancements in TMS VCL UI Pack -
Friday 5
- TMS components and Delphi and C++Builder 12.1 -
Wednesday 3
- Customizing the login page of your application using TMS Sphinx
- A Python library for using StellarDS.io effortlessly
- Introducing: How it Works with Holger - Building a Pexels gallery app with TMS WEB Core video series
- TMS FNC Cloud Pack with StellarDS.io backend: unparalleled productivity in VCL & FMX
Authors
- Bernard Roussely (1)
- Wagner Landgraf (82)
- Roman Yankovsky (2)
- Bart Holvoet (27)
- Aaron Decramer (18)
- Pieter Scheldeman (99)
- Nancy Lescouhier (32)
- Adrian Gallero (33)
- Bruno Fierens (403)
- Marcos Douglas B. Santos (5)
- Wagner R. Landgraf (1)
- Bradley Velghe (16)
- Bernard (2)
- Andrew Simard (86)
- Holger Flick (15)
- Gjalt Vanhouwaert (30)
- Tunde Keller (22)
- Masiha Zemarai (119)
Blog
All Blog Posts | Next Post | Previous PostTMS WEB Core v1.2 tips & tricks part 2 : file access from Electron apps
Bookmarks:Wednesday, June 19, 2019
In the previous blog article, we showed how the TWebFilePicker or TWebFileUpload component in TMS WEB Core are the intermediates to get read access to local files and how the Application.Download* methods can be used to write data back to the local file system. These mechanisms are required because the web application runs in the secure browser sandbox.For Electron apps, which are native desktop executable applications running on Windows, macOS64 or Linux, this is different and via Electron direct local file access is possible. From a TMS WEB Core application we have enabled a couple of easy to use methods to access such local files.
Read and write text files
To make it easy, the TElectronStringList class is available where the TElectronStringList.SaveToFile() / TElectronStringList.LoadFromFile() methods will directly read or write text files on the local device filesystem.
As such, it is possible to load a TWebRichEdit from a local HTML file directly via:
var LEsl: TElectronStringList; begin LEsl := TElectronStringList.Create; try LEsl.LoadFromFile('myappmyhtmlfile.html'); WebRichEdit1.Lines.Assign(LEsl); finally LEsl.Free; end; end;
var LEsl: TElectronStringList; begin If ElectronOpenDialog1.Execute then begin LEsl := TElectronStringList.Create; try LEsl.LoadFromFile(ElectronOpenDialog1.FileName); WebRichEdit1.Lines.Assign(LEsl); finally LEsl.Free; end; end; end;
While the TElectronStringList offers a great and easy to use way to work with text files, the TElectronBinaryDataStream gives access to any file type on the local file system. Using TElectronBinaryDataStream, the file can be retrieved as string but now additionally the data can be retrieved as base64 string or as JavaScript array buffer.
In this example code snippet, a JPEG image file is read from the local file system and displayed via a TWebImageControl
var LEbs: TElectronBinaryDataStream; begin ElectronOpenDialog1.Filters := 'Image files|*.jpg;*.jpeg'; If ElectronOpenDialog1.Execute then begin LEbs := TElectronBinaryDataStream.Create; try LEbs.LoadFromFile(ElectronOpenDialog1.FileName); WebImageControl.URL := 'data:image/jpeg;base64,' + LEbs.Base64; finally LEbs.Free; end; end; end;
Don't miss out and get started today with TMS WEB Core! You can download the trial version, go ahead with the standalone version you purchased or with TMS WEB Core and additional tools that are all included in TMS ALL-ACCESS. Our team looks forward to all your comments, feedback, feature-requests to help steering the development of TMS WEB Core to the next stages!
Bruno Fierens
Bookmarks:
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post