Skip to content

MobileCRM.Application.readFileAsBase64

rescocrm edited this page May 15, 2023 · 9 revisions

Reads the file from the application local data and asynchronously gets its base64-encoded content.

Arguments

Argument Type Description
path String Defines the relative path of the file in the application local data.
success function(result) A callback function for successful asynchronous result. The result will carry a string with the base64-encoded file content.
failed function(error) A callback function for command failure. The error argument will carry the error message.
scope A scope for calling the callbacks; set "null" to call the callbacks in global scope.

This example demonstrates how to load the image from application storage if exists and show it in <img> element.

var imagePath = "Images/MobileCrm/Images.MonoTouch/Logo/Logo@2x.png";
MobileCRM.Application.fileExists(imagePath, function (exists) {
	if (exists) {
		MobileCRM.Application.readFileAsBase64(imagePath, function (data) {
			var imgElement = document.getElementById("test-image");
			if (imgElement)
				imgElement.src = "data:image/jpeg;base64," + data;
		}, MobileCRM.bridge.alert);
	}
	else
		MobileCRM.bridge.alert("File '" + imagePath + "' doesnt'exist");
});
Clone this wiki locally