For some time have been looking for a solution on how to upload a file into BLOB with RTC Client. The built in functions, UPLOAD and UPLOADINTOSTREAM both force an Open Dialog unless you first copy the file to a temporary path. I already had the file name and wanted to skip that part.
I always stopped on the fact that I was unable to move binary data with code from the client layer to the server layer. Then today, I finally got an idea on how to solve this. I convert the client file to a base64 string, transfer that string to the server layer and save as a file. Then I create a binary server file based on the base64 server file. That file is identical to the client file and ready to be imported into BLOB on the server side.
[code htmlscript=”false”]IF ISSERVICETIER THEN BEGIN
Document.ADDTEXT(
ClientConvert.ToBase64String(
ClientFile.ReadAllBytes(ImageFileName)));
ServerBase64FileName := ThreeTireMgt.ServerTempFileName(”,”);
ServerFileStream.WRITEMODE(TRUE);
ServerFileStream.CREATE(ServerBase64FileName);
ServerFileStream.CREATEOUTSTREAM(OutStr);
Document.WRITE(OutStr);
ServerFileStream.CLOSE;
ServerDocumentFileName := ThreeTireMgt.ServerTempFileName(”,”);
ServerDocumentFile.WriteAllBytes(
ServerDocumentFileName,
ServerConvert.FromBase64String(
ServerBase64File.ReadAllText(ServerBase64FileName)));
ServerFileStream.OPEN(ServerDocumentFileName);
ServerFileStream.CREATEINSTREAM(InStr);
Image.CREATEOUTSTREAM(OutStr);
COPYSTREAM(OutStr,InStr);
ServerFileStream.CLOSE;
ServerBase64File.Delete(ServerBase64FileName);
ServerDocumentFile.Delete(ServerDocumentFileName);
END ELSE BEGIN
Image.IMPORT(ImageFileName,FALSE);
END;[/code]
This should support files upto 1.5GB in size.
Nice! I wonder why something similar has not been included to Company Information page by default.
Hi, could you attach C/AL Local declaration please?
Hi, Thank you very much. Please could you attach C/AL Local Declaration please?
Hi Marek
You should be able to download the attached file (https://dynamics.is/?attachment_id=531) and in there you should find both fob and txt objects.
Hi Gunnar,
Many thanks for your post. It helped me add the functionality in a NAV2016 system. I only had to make a few changes to the code you posted.
Thanks again.