Skip to main content
1-Visitor
February 14, 2017
Solved

Programmatically creating a MediaEntity from a file in a File Repository

  • February 14, 2017
  • 4 replies
  • 2623 views

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

Best answer by posipova

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);

4 replies

posipova20-TurquoiseAnswer
20-Turquoise
February 14, 2017

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);

5-Regular Member
February 15, 2017

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

ashleyg1-VisitorAuthor
1-Visitor
February 15, 2017

Thank you Ryan.