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

How to load the image into thingworx storage media dynamically

  • August 10, 2018
  • 1 reply
  • 4450 views

Hi,

 

Could you give the example for how to load the image dynamically.

Example: user has to load the image from local system at run time(C: drive ).

 

Thank you.

Best answer by cbuse

Hi,

 

The widget fileupload allows the user to select a file from the file system and upload it in a ThingWorx FileRepository. 

From the file repository, the image can be saved as a media entity.

 

// load the image from ThingWorx file repository
var paramsLoadImage = {
  path: imagePath /* STRING */
};
var imageContent = Things[repositoryName].LoadImage(paramsLoadImage);

// create a media entity
var paramsCreateMediaEntity = {
  name: imageName /* STRING */,
  content: imageContent /* 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

1 reply

cbuse13-AquamarineAnswer
13-Aquamarine
August 13, 2018

Hi,

 

The widget fileupload allows the user to select a file from the file system and upload it in a ThingWorx FileRepository. 

From the file repository, the image can be saved as a media entity.

 

// load the image from ThingWorx file repository
var paramsLoadImage = {
  path: imagePath /* STRING */
};
var imageContent = Things[repositoryName].LoadImage(paramsLoadImage);

// create a media entity
var paramsCreateMediaEntity = {
  name: imageName /* STRING */,
  content: imageContent /* 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 solution. Its working for me