Skip to main content
16-Pearl
August 13, 2018
Solved

How to assign the Image to Image widget

  • August 13, 2018
  • 6 replies
  • 6165 views

Hi,

 

I want to assign the Image to Image Widget. How to achieve.

Image is available in the SystemRepository

In Below service,I am loading the image and return the Image type

 

var params = {

path: MyImagefullpath /* STRING */

};

var result = Things["SystemRepository"].LoadImage(params);  // Here result type is Image type

 

In Mashup , I am trying to bind the result value to Image Widget. It is not accepting.

Could you please advise how to assign the image(Image in SystemRepository) to Image Widget. 

 

Thank You

 

Best answer by cbuse

var imageName = "mediaEntityName";

var result = "";

if (MediaEntities[imageName]) {
  result = "Media entity already exists";
}
else {
  result = "Media entity does not exist";
}

6 replies

13-Aquamarine
August 13, 2018

Hi,

 

The input for the Image widget needs to be of type IMAGELINK and it looks like this: /ThingWorx/MediaEntities/imageName

 

Use the image returned from LoadImage service as input for creating a media entity.

 

// create a media entity 
var paramsCreateMediaEntity = {
  name: imageName /* STRING */,
  content: loadImageResult /* IMAGE */
};
Resources["EntityServices"].CreateMediaEntity(paramsCreateMediaEntity);

// output the source URL of the media entity which can be used as input for the image widget
var result = "/Thingworx/MediaEntities/" + imageName

vi116-PearlAuthor
16-Pearl
August 13, 2018

Thank you for the solution. Its working for me.

 

How to check the condition if Media entity with same name available or not before creating media entity.

 

Thank you

cbuse13-AquamarineAnswer
13-Aquamarine
August 13, 2018

var imageName = "mediaEntityName";

var result = "";

if (MediaEntities[imageName]) {
  result = "Media entity already exists";
}
else {
  result = "Media entity does not exist";
}