How to get binary data of image for client side action for mobile app

How to get binary data of image for client side action for mobile app

  

Hi.

I'm creating a mobile app and i noticed that when an image comes from dynamic data (image url), it is not loaded in the page. further digging in the forums that I must convert image to binary data and set the it's appropriate image type. 

tried doing it in javascript and nothing comes up.

here is 1 code i used.

var refURL = $parameters.URL
var imgData = null;
var img = new Image();
img.onload = function (){
    var canvas = document.createElement('canvas');
    canvas.getContext('2d').drawImage(this,0,0);
    imgData = canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, '');
}
img.src = refURL;
$parameters.returnValue = imgData;

here's anothe one

var refURL = $parameters.URL
var blob = null;
var img = new Image();
var dataURL = null;
var xhr = new XMLHttpRequest();
    xhr.open('GET', refURL,true );
    xhr.responseType = 'blob';
    xhr.setRequestHeader("Access-Control-Allow-Origin","*")
    xhr.onreadystatechange = function () {
      if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
            alert('Success: ' + xhr.responseText);  }
        else
        {  alert('Error submitting image: \r\n ReadyState: ' + xhr.readyState + "\n Status: " + xhr.status + ' \r\n' + refURL);  }
    };
    xhr.send();
    img.src = refURL;
    blob = new Blob([xhr.response],{type: "image/png"})  
$parameters.returnValue = blob;


thanks

Hi Kux,

Add an image to your screen, and set

Type property to External URL

URL property to the URL link or variable that contains the URL link.

That's it. The image will not show up in your service studio, but it will do when you run the app.

Regards,

Daniel

Daniël Kuhlmann wrote:

Hi Kux,

Add an image to your screen, and set

Type property to External URL

URL property to the URL link or variable that contains the URL link.

That's it. The image will not show up in your service studio, but it will do when you run the app.

Regards,

Daniel

Hi Daniel,

Thanks. originally it's like that. but i am going to use it in a native mobile app. images dont load if it comes from a dynamic source. only images that have been initially rendered when the app was generated i.e. css images. 

thanks and regards

KuX