Skip to main content

Notifications

Small and medium business | Business Central, N...
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 71,565 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

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,275 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans