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

Programmatically creating a MediaEntity from a file in a File Repository

ashleyg
1-Newbie

Programmatically creating a MediaEntity from a file in a File Repository

Is it possible to create a Media Entity from a file in a File Repository?

I have attempted to access a File Repository's files through the REST API but don't think this is possible without executing RES API services of which I am unsure how to implement.

Is there a more simpler way of creating Media Entities from Images uploaded to a File Repository?

Many Thanks

Ashley

1 ACCEPTED SOLUTION

Accepted Solutions
posipova
20-Turquoise
(To:ashleyg)

Hi Ashley,

For example, we have a FileRepository named ImageFile, with a folder "test" that contains an image "test". Then we have a Thing with a service "LoadFrom Rep". It contains the following  service to load/access the image contained in the filerepository ImageFIle. This is the service (result output set to Image):

var params = {

  path: '/test/test.jpg' /* STRING */

};

// result: IMAGE

var Content1= Things["ImageFIle"].LoadImage(params);

result=Content1;


Similarly, we may then expand the service to load that image to a media entity (in this scenario I'm creating a new entity):

var params = {

  name: 'NewMedia' /* STRING */,

  content: Content1 /* IMAGE */,

};

// no return

Resources["EntityServices"].CreateMediaEntity(params);

View solution in original post

4 REPLIES 4
posipova
20-Turquoise
(To:ashleyg)

Hi Ashley,

For example, we have a FileRepository named ImageFile, with a folder "test" that contains an image "test". Then we have a Thing with a service "LoadFrom Rep". It contains the following  service to load/access the image contained in the filerepository ImageFIle. This is the service (result output set to Image):

var params = {

  path: '/test/test.jpg' /* STRING */

};

// result: IMAGE

var Content1= Things["ImageFIle"].LoadImage(params);

result=Content1;


Similarly, we may then expand the service to load that image to a media entity (in this scenario I'm creating a new entity):

var params = {

  name: 'NewMedia' /* STRING */,

  content: Content1 /* IMAGE */,

};

// no return

Resources["EntityServices"].CreateMediaEntity(params);

Hi Ashley,

Following Polina's steps, you can set the image Path,  the image file Name and Media ThingName as three input to this service, and then you can use REST API calls to create more media entities from the image files remotely

ashleyg
1-Newbie
(To:zyuan1)

Thank you Ryan.

Thank you for this Polina!

Announcements