Skip to main content
1-Visitor
Dec 9, 2016 6:54 AM UTC
Question

How to set image in media entity dynamically?

Hi,

i am trying to set the image in media entity dynamically, using following code snippet :

var params = {

  url: path /* STRING */,

};

// result: IMAGE

var result = Resources["ContentLoaderFunctions"].LoadImage(params);

getting below exception:

clientprotocolexception null

Any new suggestion for doing it?

Thanks in advance!

2 replies

5-Regular Member
Dec 9, 2016 11:50 PM UTC

What are you passing in as the path?

Translate
20-Turquoise
Dec 13, 2016 3:13 PM UTC

Assuming you already have a media entity named "TestMedia", here's an example of how to make it work via service. You may input a url and plug it in, you may also create an entity using a snippet, but here's the general idea and a hardcoded example that works. Let me know if you need any further details.

var params = {

  url:  'https://pbs.twimg.com/profile_images/447374371917922304/P4BzupWu.jpeg' /* STRING */,

};

// result: IMAGE

var image = Resources["ContentLoaderFunctions"].LoadImage(params);

var params = {

  name: 'TestMedia'/* STRING */,

  content: image

};

// no return

Resources["EntityServices"].UpdateMediaEntity(params);

Translate