Media Server
The Platform includes a simple file storage solution, Media Server. The purpose of this component is to provide a simple API (HTTP REST) to store and retrieve files of arbitrary nature which are attached to PixelCore’s Media Objects. Files are being stored in the PostgreSQL database.
The Platform includes a simple file storage solution, Media Server. The purpose of this component is to provide a simple API (HTTP REST) to store and retrieve files of arbitrary nature which are attached to PixelCore’s Media Objects. Files are being stored in the PostgreSQL database.
Media Objects and Media Server Shemas¶
Media Server maintains two Schemas in PixelCore, one is called “Media File” and another “Generic Media Server”.
Media File Schema has to be used to instantiate regular Objects and then Object’s UUID can be used to store (and access) a file with Media Server’s provided HTTP API.
Generic Media Server Schema is used by Media Server itself to maintain one Object in PixelCore which represents actual status of Media Server process and some associated statistics (total number of files in the storage, total size and some other useful information). This Object is updated by the Media Server process on a regular or event basis for statistics and status changes.
Authorization¶
To be able to work with Media Server API one has to obtain a valid authorization token via standard PixelCore authorization procedure. Media Server verifies the validity of presented the token and access rights to provided Media Object as well.
Retrieve a media file¶
To retrieve a file from the media server you will need the UUID of the media object associated with the file and JWT token. Make a GET request at:
http://127.0.0.1:3000/download/${UUID} with cookie ‘jwt=${JWT}’
When you make this request, the media server does the following:
- Using the JWT provided, the media server gets the access status of the application for the media object.
- If the application does not have access to the object with the given UUID the media server returns an unauthorized status.
- If the application does have access to the object the media server retrieves the corresponding data from the PixelCore and returns it to the requestor.
- The data is served with content type set to the MIME type stored in the value of the ‘MEDIA_TYPE’ property associated with the Media Object. If this value is not set the content type default to text/plain.
Upload a media file¶
To upload a file to the media server you will need the UUID of the media object associated with the file and your JWT. Make a POST request at:
http://127.0.0.1:3000/upload/${UUID} with cookie ‘jwt=${JWT}’
The file has to be provided as form-data with the name set to ‘uploaded_file’.
When you make this http request, the media server does the following:
- Using the JWT provided, the media server gets the access status of the application for the media object.
- If the application has editor or user access it is allowed to upload the file, otherwise the Media Server returns an unauthorized status.
- The Media Server updates the corresponding data in the media table with the file encoded in bytea format.