Skip to main content
Aug 13, 2018 12:06 PM UTC
Solved

How to assign the Image to Image widget

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

 

cbuseAnswer
Aug 13, 2018 3:01 PM UTC

var imageName = "mediaEntityName";

var result = "";

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

6 replies

Aug 13, 2018 1:30 PM UTC

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

vi1Author
Aug 13, 2018 2:55 PM UTC

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

cbuseAnswer
Aug 13, 2018 3:01 PM UTC

var imageName = "mediaEntityName";

var result = "";

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