cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to load the image into thingworx storage media dynamically

SOLVED
Highlighted
vi1
Level 8

How to load the image into thingworx storage media dynamically

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.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to load the image into thingworx storage media dynamically

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

2 REPLIES

Re: How to load the image into thingworx storage media dynamically

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

Re: How to load the image into thingworx storage media dynamically

Thank You for solution. Its working for me