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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

How to load the image into thingworx storage media dynamically

InfinityX
15-Moonstone

How to load the image into thingworx storage media dynamically

As I tried the below article but getting some error

How to load the image into thingworx storage media dynamically 

 

Getting some error

 The filename, directory name, or volume label syntax is incorrect]

ACCEPTED SOLUTION

Accepted Solutions
cmorfin
19-Tanzanite
(To:InfinityX)

Hi @InfinityX 

 

The problem is still with the path setting.

You are using 

Things["SystemRepository"].LoadImage(paramsLoadImage);

this means that the FileRepository SystemRepository is used to load image.

This FileRepository is only going to look inside its root folder and nowhere else on the machine, so the path needs to be relative to this root folder.

Based on what you wrote your SystemRepository is pointing to C:\Program Files (x86)\ThingWorxPostgres-8.4.8\ThingworxStorage\repository\SystemRepository. So this is where 

Things["SystemRepository"].LoadImage(paramsLoadImage); is going to look for data.

The path specified in paramsLoadImage needs to be something inside this folder.

Specifying the full path as you did does not work.

If your image file is directly under C:\Program Files (x86)\ThingWorxPostgres-8.4.8\ThingworxStorage\repository\SystemRepository, then path should simply be the image file name, for example image.png.

The path needs to point to the file itself not the parent folder.

 

The imageName is the name that will be displayed in Composer for this Media entity, it has not got to be the same as filename, but path does need to point to the filename.

 

I hope that clarifies it.

Regards

Christophe

 

View solution in original post

7 REPLIES 7
cmorfin
19-Tanzanite
(To:InfinityX)

Hi @InfinityX 

 

Something that would give this error is you enter incorrect value for imagePath .

imagePath  should be relative to the Repository you are using.

For example if you have mypic.jpg sotred under SystemRepository, imagePath  should be mypic.jpg only.

 

Hope this helps

Christophe

 

 

InfinityX
15-Moonstone
(To:cmorfin)

Yes,

I tried with the help of file upload widget, it's working. But as I tried with other file location defined in the service getting error for location of file.

So, What should I do for other location image file to show on mashup.

My requirement is to show the single images for 3 second on image widget, after 3 second next image will show. 

cmorfin
19-Tanzanite
(To:InfinityX)

Hi @InfinityX 

The code you referred to at https://community.ptc.com/t5/ThingWorx-Developers/How-to-load-the-image-into-thingworx-storage-media-dynamically/td-p/565635  does require the file to be present under a ThingWorx FileRepository.

I don't think you can show files outside a filerepository, would be a potential security issue.

 

Regards

Christophe

 

InfinityX
15-Moonstone
(To:cmorfin)

Okay, Then I'll all upload all files in system repository directory. 

Then as per your code can I able to do some changes 

var paramsLoadImage = {
path: "E:\WallpaperImages" /* STRING */    // here can I assign as over here system repository directory location
};var imageContent = Things["SystemRepository"].LoadImage(paramsLoadImage);

for (var i=1;i<10;i++){

// create a media entity
var imageName= imageName;   /// Here image file name in loop in array
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;

// pause():INTEGER
var milliseconds = pause(2000);  // 2 second delay

}  // for complete

cmorfin
19-Tanzanite
(To:InfinityX)

Hi @InfinityX 

 

You can update the service as you wish for your need.

 

However remember that the imagepath is a path within a filereposidtory not an absolute path of style E:\MyDir.

Also if you want to have this executed in a loop, I think the 

var paramsLoadImage = {
path: "E:\WallpaperImages" /* STRING */    // here can I assign as over here system repository directory location
};var imageContent = Things["SystemRepository"].LoadImage(paramsLoadImage);

will have to be in a loop since it points to the actual image file, so I suppose it will need changing for each media entity.

 

Regards

Christophe

 

InfinityX
15-Moonstone
(To:cmorfin)

As per your assist I have did some changes in the code; I'm getting some error and I have attached my code with you.

Code:

var i;
for (i=1;i<10;i++){
var paramsLoadImage = {
path: "C:\Program Files (x86)\ThingWorxPostgres-8.4.8\ThingworxStorage\repository\SystemRepository" /* STRING */
};
var imageContent = Things["SystemRepository"].LoadImage(paramsLoadImage);
// create a media entity
var imageName= "Image"+[i]+".png";
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;

// pause():INTEGER
var milliseconds = pause(2000);
}

 

Error :

Invalid child path: Child path failed validation

 

cmorfin
19-Tanzanite
(To:InfinityX)

Hi @InfinityX 

 

The problem is still with the path setting.

You are using 

Things["SystemRepository"].LoadImage(paramsLoadImage);

this means that the FileRepository SystemRepository is used to load image.

This FileRepository is only going to look inside its root folder and nowhere else on the machine, so the path needs to be relative to this root folder.

Based on what you wrote your SystemRepository is pointing to C:\Program Files (x86)\ThingWorxPostgres-8.4.8\ThingworxStorage\repository\SystemRepository. So this is where 

Things["SystemRepository"].LoadImage(paramsLoadImage); is going to look for data.

The path specified in paramsLoadImage needs to be something inside this folder.

Specifying the full path as you did does not work.

If your image file is directly under C:\Program Files (x86)\ThingWorxPostgres-8.4.8\ThingworxStorage\repository\SystemRepository, then path should simply be the image file name, for example image.png.

The path needs to point to the file itself not the parent folder.

 

The imageName is the name that will be displayed in Composer for this Media entity, it has not got to be the same as filename, but path does need to point to the filename.

 

I hope that clarifies it.

Regards

Christophe

 

Announcements


Top Tags