Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Upload and then compress a file to gzip in BC14

Posted on by 5

Hello,

How can I modify my existing code to successfully convert a file into a gzip file and then encode it to a base64 string on BC14? Our customer is on this system for at least 2 more years, and despite multiple attempts, the current implementation does not work. It fails on the line  StreamMgt.WriteGzipStreamToTempBlob() because the DotNet_GZipStream is not readable.
Here is the code I'm currently using:


             procedure UploadAndCompress()

             var

                    FileName: Text;

                    GZipAsText: Text;

                    InStream: InStream;

                    OutStream: OutStream;

 

                    DotNet_GZipStream: Codeunit DotNet_GZipStream;

                    DotNet_CompressionMode: Codeunit DotNet_CompressionMode;

                    StreamMgt: Codeunit /Stream Management/;

                    TempBlob: Record TempBlob;

                    TempBlob2: Record TempBlob;

                begin

                    FileName := 'c://SomeFile.txt';

                    UploadIntoStream('Import', '', ' All Files (*.*)|*.*', FileName, InStream);


 

                    TempBlob.Blob.CreateOutStream(OutStream);

                    CopyStream(OutStream, InStream);

                    DotNet_CompressionMode.Compress();

                    StreamMgt.InitGzipStreamFromTempBlob(TempBlob, DotNet_CompressionMode, DotNet_GZipStream);

 

                    StreamMgt.WriteGzipStreamToTempBlob(DotNet_GZipStream, TempBlob2);

                    GZipAsText := TempBlob2.ToBase64String();

 

                    DotNet_GZipStream.CLOSE();

                end;

  • EN-18061927-0 Profile Picture
    EN-18061927-0 2 on at
    Upload and then compress a file to gzip in BC14
    Hi, did you ever find a solution to this problem? I am trying to decompress a gzipped stream on BC 14 but I run into the same issue at the  StreamMgt.WriteGzipStreamToTempBlob(DotNet_GZipStream, TempBlob2); step, where the GZip_Stream is not writable.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,395 Super User 2024 Season 2 on at
    Upload and then compress a file to gzip in BC14
    Hi, Sorry I'm not sure if this is supported in BC14, but hopefully it can give you some hints.
    How to bulk export/download attachments (Downloading multiple attachments via zip file) – Customization
     
    How to convert Image (item picture) to encoded text (Base64 String) via AL
     
     
    Thanks.
    ZHU

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans