The trouble is you think you have time. Your success depends on how you utilize your time.

Browse and select the file or image and save it into the container field of table

Browse and upload file/image, get its path to convert it to base64 then put that into the container and save it into the table.


        public static void main(Args _args)

    {

        Str1260 fileUrl;

        BinData binData = new BinData();

        container imageContainer;

        ListIterator    iterator;

        List urls =  new List(Types::String);

        str finalUrl = '';

        MZNUKEmployeeSignature currentRec;


        if  (tableNum(MZNUKEmployeeSignature) == _args.dataset())

        {

            currentRec = _args.record();

        }

       

        FileUploadTemporaryStorageResult result = File::GetFileFromUser() as                FileUploadTemporaryStorageResult;

        If(result && result.getUploadStatus())

        {

            fileUrl = result.getDownloadUrl();            

            urls = strSplit(fileUrl, '?');

            int i = 1;

            iterator = new ListIterator(urls);

            while(iterator.more())

            {

                if (i == 1)

                    finalUrl = iterator.value();


                i++;

                iterator.next();

            }

        }

        

        System.Drawing.Image image;

        System.IO.MemoryStream memoryStream;

        str fileEncoded = '';


        System.Net.WebRequest req = System.Net.WebRequest::Create(fileUrl);

        System.Net.WebResponse resp = req.GetResponse();

        System.IO.Stream stream = resp.GetResponseStream();

        Filename filepath;

        Filename filename;

        Filename fileType;

        [filepath, filename, fileType] = fileNameSplit(finalUrl);


        image = System.Drawing.Image::FromStream(stream);

        memoryStream = new System.IO.MemoryStream();



        if ( strUpr(any2str(fileType)) == '.JPEG')

            image.Save(memoryStream, System.Drawing.Imaging.ImageFormat::Jpeg);

        else if ( strUpr(any2str(fileType)) == '.PNG')

            image.Save(memoryStream, System.Drawing.Imaging.ImageFormat::Png);

        else if ( strUpr(any2str(fileType)) == '.BMP')

            image.Save(memoryStream, System.Drawing.Imaging.ImageFormat::Bmp);

        else

            image.Save(memoryStream, System.Drawing.Imaging.ImageFormat::Bmp);

               

        fileEncoded = System.Convert::ToBase64String(memoryStream.ToArray());

        imageContainer = BinData::loadFromBase64(fileEncoded);

        currentRec.EmployeeSignature = imageContainer;

        currentRec.update();

        Info('Action Completed.');

}


Read how to make UIBuilder Class Click Here

Read how to make DP class for Contact Click Here

DP Class for UI Builder ListEnumerator d365 x++ Finance and Operations 

No comments:

Post a Comment