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 64,563 Super User 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

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans