<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: [SAP MDK] Converting Binary to Base64 for Android/iOS in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sap-mdk-converting-binary-to-base64-for-android-ios/qaa-p/13954941#M4894903</link>
    <description>&lt;P&gt;Hello Khaled&lt;/P&gt;&lt;P&gt;Good news, MDK 24.11.0 which was just released last week introduced this new API:&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/3642933ef2e1478fb1578ef2acba4ae9/Latest/en-US/reference/apidoc/classes/clientapi.html#binarytobase64string" target="_self"&gt;binaryToBase64String&lt;/A&gt;&amp;nbsp;on the ClientAPI class&lt;/P&gt;&lt;P&gt;Here's an example using your initial sample code as base.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export default async function getImageString(clientAPI) {
    var attachmControl = clientAPI.getPageProxy().getControl('SectionedTable0').getControl('AttachPhoto');
    var arrayBuffer = attachmControl.getValue()[0].content;
    var base64str = await clientAPI.binaryToBase64String(arrayBuffer);
    return base64str;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Dec 2024 06:28:11 GMT</pubDate>
    <dc:creator>mingkho</dc:creator>
    <dc:date>2024-12-04T06:28:11Z</dc:date>
    <item>
      <title>[SAP MDK] Converting Binary to Base64 for Android/iOS</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-mdk-converting-binary-to-base64-for-android-ios/qaq-p/13954696</link>
      <description>&lt;P&gt;Hello MDK Community,&lt;/P&gt;&lt;P&gt;I am currently developing an application using MDK &amp;amp; Mobile Services, which needs to send a photo (from the attachment) to the SAP backend via REST upon pressing a button.&lt;BR /&gt;I have developed the following MDK rule (getImageString.js) to perform the conversion from the image obj to base64:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export default function getImageString(clientAPI) {
    var attachmControl = clientAPI.getPageProxy().getControl('SectionedTable0').getControl('AttachPhoto');
    var arrayBuffer = attachmControl.getValue()[0].content;
    return arrayBufferToBase64(arrayBuffer);
}

function arrayBufferToBase64(buffer) {
    var binary = '';
    var bytes = new Uint8Array(buffer);
    var len = bytes.byteLength;
    
    for (var i = 0; i &amp;lt; len; i++) {
        binary += String.fromCharCode(bytes[i]);
    }
    return window.btoa(binary);  //here is the problem!
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;This script works fine in the browser (WebApp), but it fails on mobile devices (tested on an Android device) &lt;STRONG&gt;at the point of converting binary to base64&lt;/STRONG&gt; due to the use of the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;window, which is likely not recognized on mobile devices. The issue specifically occurs at the line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return window.btoa(binary);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;Question:&lt;/H3&gt;&lt;P&gt;Is there an alternative method to convert &lt;STRONG&gt;&lt;U&gt;binary to base64&lt;/U&gt;&lt;/STRONG&gt; that works on mobile devices (Android/iOS) or a method from the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;clientAPI&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;interface that can be used for this conversion?&lt;BR /&gt;I am open to alternative solutions to achieve this functionality.&lt;/P&gt;&lt;P&gt;For reference, I'm using SAP Mobile Services for the backend orchestration and the latest MDK client version.&lt;BR /&gt;Thank you in advance for your assistance!&lt;BR /&gt;Best regards,&amp;nbsp;Khaled&lt;/P&gt;&lt;P&gt;PS: For simplicity, this example assumes only one attachment.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 23:59:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-mdk-converting-binary-to-base64-for-android-ios/qaq-p/13954696</guid>
      <dc:creator>Khaled_Elghali</dc:creator>
      <dc:date>2024-12-03T23:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: [SAP MDK] Converting Binary to Base64 for Android/iOS</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-mdk-converting-binary-to-base64-for-android-ios/qaa-p/13954941#M4894903</link>
      <description>&lt;P&gt;Hello Khaled&lt;/P&gt;&lt;P&gt;Good news, MDK 24.11.0 which was just released last week introduced this new API:&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/3642933ef2e1478fb1578ef2acba4ae9/Latest/en-US/reference/apidoc/classes/clientapi.html#binarytobase64string" target="_self"&gt;binaryToBase64String&lt;/A&gt;&amp;nbsp;on the ClientAPI class&lt;/P&gt;&lt;P&gt;Here's an example using your initial sample code as base.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export default async function getImageString(clientAPI) {
    var attachmControl = clientAPI.getPageProxy().getControl('SectionedTable0').getControl('AttachPhoto');
    var arrayBuffer = attachmControl.getValue()[0].content;
    var base64str = await clientAPI.binaryToBase64String(arrayBuffer);
    return base64str;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 06:28:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-mdk-converting-binary-to-base64-for-android-ios/qaa-p/13954941#M4894903</guid>
      <dc:creator>mingkho</dc:creator>
      <dc:date>2024-12-04T06:28:11Z</dc:date>
    </item>
  </channel>
</rss>

