Skip to main content

Notifications

Announcements

No record found.

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 76,221 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans