Look at BASE64 ENCODE / DECODE https://doc.4d.com/4Dv17/4D/17.4/BASE64-DECODE.301-4882388.en.html
Peter Bozek On Fri, Apr 24, 2020 at 9:05 AM Chris Belanger via 4D_Tech < 4d_tech@lists.4d.com> wrote: > ORDA does not support BLOB fields. So I need a different way of storing > things that would normally be BLOBS as TEXT. > (in particular, system DOCUMENTS such as PDFS, JPGS, etc). > > I am trying to work-around by converting BLOB -> TEXT -> BLOB > ———— > The key statements to work around the ‘BLOB’ problem are: > $en_Lib.UpdBLOBText:=Convert to text($blob_File;"UTF-16") // To save > the BLOB as a TEXT field > > CONVERT FROM TEXT([Lib]UpdBLOBText;"UTF-16";$Blob) // to > convert the TEXT back into a BLOB, so it can be written as a system document > ———— > > I am not actually storing the documents in the database, but wanting to > have a mechanism to ‘transport’ a document to the 4D Server so it can > manage the document creation ‘on disk’ in the TRIGGER. Basically, I am > managing a ‘LIBRARY’ of documents that are stored on the machine hosting 4D > Server. > > My methodology seems to works fine: > > EXPLANATION: > • on CLIENT: Document is read from Disk [as a BLOB], converted to a TEXT > field and SAVED. [Lib] > • on 4D SERVER: In the [Lib] Trigger method, if there are contents in > [Lib]UpdBLOBText, then the update is made in the document library > then, the [Lib]UpdBLOBText field is BLANKED OUT so reduce data > size, obviously. > > // ON THE CLIENT MACHINE: > // READ THE CONTENTS OF A FILE FROM DISK, STORING IT INTO THE > [Lib]UpdBLOBText field to be processed by its TRIGGER on SAVE > > $droppedFile is a FILE OBJECT made with File( path ). The object is > good. I use the ‘Folder&Files’ methodology: > $blob_File:=$droppedFile.getContent() // > get the contents of the disk file as a BLOB (which was dropped onto a drop > variable) > $en_Lib.UpdBLOBText:=Convert to text($blob_File;"UTF-16") // update > this to the UpdBLOBText. > > > // WHEN A [Lib] RECORD IS SAVED, THEN IN THE [Lib] TRIGGER the following > is done on the 4D Server machine: > // > ….. > > $theFile:=File(Storage.folder_docLibrary.path+$localPath) // > set up the DESTINATION ON DISK for this file > CONVERT FROM TEXT([Lib]UpdBLOBText;"UTF-16";$Blob) // convert > the TEXT back into a BLOB > $theFile.setContent($Blob) > // deposit the BLOB into the disk File > [Lib]UpdBLOBText:=“” > // CLEAR OUT ITS CONTENTS > > ———— > > For a number of file types, this works fine. But for MS Word documents I > get a warning when I open them up: > "Word found unreadable content in "2002001A Permit 1 Chris Belanger > IS-821A.docx". Do you want to recover the contents of this document? If you > trust the source of this document, click Yes.” > > When I Click YES, the document appears to be fine: no visible mess-up. > But I suspect my BLOB Work-Around is messing with the file contents in > some way. > > What are the best parameters to use for converting BLOB -> TEXT -> BLOB ? > > Thanks, > Chris > > ********************************************************************** > 4D Internet Users Group (4D iNUG) > Archive: http://lists.4d.com/archives.html > Options: https://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:4d_tech-unsubscr...@lists.4d.com > ********************************************************************** -- -- Peter Bozek ********************************************************************** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **********************************************************************