Tuesday, November 9, 2021

NAV 2016 - Save Image Blob File on Server - Convert from Base 64

 Hello Friends,

Today we received request from client to save the image to server folder from base 64 image string (it will call from powerapp using NAV web service)

Below function we create for development

---------------------------------------------------

    PROCEDURE SaveDocumentImage_gFnc@33027920(DocNo_iCod@33027921 : Code[20];Image_Base64_iBigTxt@33027931 : BigText) : Boolean;

    VAR

      PurchaseHeader_lRec@33027929 : Record 38;

      RecordLink_lRec@33027920 : Record 2000000068;

      FoundRecID_lRecID@33027922 : RecordID;

      FileSaveLocalFolderFullpath_lTxt@33027923 : Text;

      FileGloabalURLPath_lTxt@33027924 : Text;

      NameofFile_lTxt@33027925 : Text;

      Bytes@33027930 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array";

      Convert@33027928 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Convert";

      MemoryStream@33027927 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream";

      OStream@33027926 : OutStream;

      TempBlob@33027932 : Record 99008535;

      IStream@33027933 : InStream;

      GLSetup_lRec@33027934 : Record 98;

      FileManagement_lCdu@33027935 : Codeunit 419;

    BEGIN

      IF DocNo_iCod = '' THEN

        ERROR('DCNo_iCod cannot be blank');


      IF FORMAT(Image_Base64_iBigTxt) = '' THEN

        ERROR('Image_Base64_iBigTxt cannot be blank');


      GLSetup_lRec.GET;

      GLSetup_lRec.TESTFIELD("Server Att Local Folder Path");

      GLSetup_lRec.TESTFIELD("Server Web Global URL for Att");


      NameofFile_lTxt := FORMAT(CURRENTDATETIME,0,'<Day,2>_<Month,2>_<Year4>_<Hours24>_<Minutes,2>_<Seconds,2>') +'_'+ FORMAT(RANDOM(100)) + '.jpg';

      FileSaveLocalFolderFullpath_lTxt := GLSetup_lRec."Server Att Local Folder Path" + NameofFile_lTxt;

      FileGloabalURLPath_lTxt := GLSetup_lRec."Server Web Global URL for Att" + NameofFile_lTxt;


      PurchaseHeader_lRec.GET(PurchaseHeader_lRec."Document Type"::Order,DocNo_iCod);

      FoundRecID_lRecID := PurchaseHeader_lRec.RECORDID;


      Bytes := Convert.FromBase64String(Image_Base64_iBigTxt);

      MemoryStream := MemoryStream.MemoryStream(Bytes);

      TempBlob.Blob.CREATEOUTSTREAM(OStream);

      TempBlob.Blob.CREATEINSTREAM(IStream);

      MemoryStream.WriteTo(OStream);


      FileManagement_lCdu.BLOBExportToServerFile(TempBlob,FileSaveLocalFolderFullpath_lTxt);


      //SaveImageAttachment_lFnc(Image_Base64_iBigTxt,GateEntryHeader_lRec);


      CLEAR(RecordLink_lRec);

      RecordLink_lRec.INIT;

      RecordLink_lRec."Record ID" := FoundRecID_lRecID;

      RecordLink_lRec.URL1 := FileGloabalURLPath_lTxt;

      RecordLink_lRec.Description := NameofFile_lTxt;

      RecordLink_lRec.Company := COMPANYNAME;

      RecordLink_lRec."User ID" := USERID;

      RecordLink_lRec.Created := CURRENTDATETIME;

      RecordLink_lRec.Type := RecordLink_lRec.Type::Link;

      RecordLink_lRec.INSERT;

      COMMIT;


      EXIT(TRUE);

    END;


==============






3 comments:

  1. Your car could be stolen if you don't keep this in mind!

    Consider that your car was taken! When you approach the police, they inquire about a specific "VIN lookup"

    A VIN decoder: What is it?

    Similar to a passport, the "VIN decoder" allows you to find out the date of the car's birth and the identity of its "parent"( manufacturing plant). You can also figure out:

    1.Type of engine

    2.Automobile model

    3.The limitations of the DMV

    4.Number of drivers in this vehicle

    The location of the car will be visible to you, and keeping in mind the code ensures your safety. The code can be viewed in the online database. The VIN is situated on various parts of the car to make it harder for thieves to steal, such as the first person seated on the floor, the frame (often in trucks and SUVs), the spar, and other areas.

    What if the VIN is intentionally harmed?

    There are numerous circumstances that can result in VIN damage, but failing to have one will have unpleasant repercussions because it is illegal to intentionally harm a VIN in order to avoid going to jail or being arrested by the police. You could receive a fine of up to 80,000 rubles and spend two years in prison. You might be held up on the road by a teacher.

    Conclusion.

    The VIN decoder may help to save your car from theft. But where can you check the car reality? This is why we exist– VIN decoders!

    ReplyDelete