Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Upload and then compress a file to gzip in BC14

(1) ShareShare
ReportReport
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 77,925 Super User 2025 Season 1 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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans