How to download Image or any file from Base64 in Dynamics 365 Business Central.
How to download Image or any file from Base64 in Dynamics 365 Business Central.
Working on Dynamics 365 Business central on cloud (SaaS) some of the customization no longer working. One of them is using blob to base64. calling Base64 methods on the TempBLOB table is not possible because those functions on the TempBLOB table are using .Net. In order to achieve the same result, we can use the Base 64 Codeunit [4110].
In this article we will convert the file from Base64 string.
In short what is Base64?
1. Base64 is the most popular binary-to-text algorithm used to convert data as plain text in order to prevent data corruption during transmission between different storage mediums.
2. In addition, it is often used to embed binary data into text documents such as HTML, CSS, JavaScript, or XML.
Read more about Base 64
/* Code in AL */
// 1. TextBase44 text variable having the value Converted Base64 string of image.
trigger OnRun()
var
Convert: Codeunit "Base64 Convert";
TempBlob: Codeunit "Temp Blob";
outstr: OutStream;
InStr: InStream;
FileManagement: Codeunit "File Management";
TextBase44: Text;
FileName: Text;
begin
TextBase44 := '/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBUVFRgVFRUYGBgaGBgYGhgYGBgYGBgYGBgZGhgYGBgcIS4lHB4rHxgYJjgmKy8xNTU1GiQ7QDs0Py40NTEBDAwMEA8QHxISHjErJCs0NDU0NDQxNDQ0NDQ0NDQ0NDE0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDE0Mf/AABEIAQ0AuwMBIgACEQEDEQH/xAAbAAABBQEBAAAAAAAAAAAAAAABAAIDBAcFBv/EAEYQAAIBAgIEBwoNBAIDAQAAAAECAAMREiEEMUFRBSJhcXOBsgYHEzJykZKx0fAVIyQzNEJSU1ShwcLSFBeTohZiY+Hxgv/EABoBAAIDAQEAAAAAAAAAAAAAAAECAAMEBQb/xAArEQACAQIEBQQCAwEAAAAAAAAAAQIDESEyUXEEEhMxMyIjQYEUYUJSkQX/2gAMAwEAAhEDEQA/ANA7qu6FtERGVA+JitixW1he+QnnG74r/c0/8h9kl75Z+KpeW3Zma0kv529cSMZSk0nYtm4wpqTV73NBPfIf7lPTPsi/uK/3VP0zM+K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w9L0F9kPPU/sT29DHre9ocPvYzYPgPRfw9L0F9kd8A6N9xT9BfZB1KmpPRoY2x97GA++U2Q9z+i/h6XoL7ID3PaL+Hpegvsh56uq/wAJ6NDGiOWNA97GbL/x/Rfw9L0F9kPwBov4en6C+yHqVdV/hPRoY0gjys2P/j2i/h6XoL7Iv+P6L+Hpegvsk6lXVf4T29DGiIQPexmx/AGi/h6XoL7I74C0X7il6C+yDqVdUT29DGrHd7+eAj3sZsnwHov4el6C+yH4D0X8PS9BfZD1KmpPb0MaA97QYeW3JYzaBwDo33FP0F9kcOAdG+4p+gvsk6lXUHtGKaFTPhqbbPCpsNhxly/KbNaTpwNo4IIoUrjMHwa3BG0G0veCXcIqi27sabTSS+D/2Q==';
TempBlob.CreateOutStream(OutStr);
Convert.FromBase64(TextBase44, OutStr);
TempBlob.CreateInStream(InStr);
FileName := 'download1.jpg';
File.DownloadFromStream(InStr, 'Download image Export', '',
FileManagement.GetToFilterText('', FileName),
FileName)
end;
Nice Article! Are you looking for the best mobile app development companies in madhapur that will be helpful for your business. We provide efficient methodologies for the successful implementation of app development company in hyderabad | mobile app development hyderabad | mobile application development company hyderabad | mobile application development companies in hyderabad | ecommerce solutions hyderabad | best mobile app development company in hyderabad | mobile application development company in hyderabad | mobile development company hyderabad | mobile app development services in hyderabad | best mobile app developers in hyderabad .
ReplyDeleteThank you!