Introduction
The MK.IO API allows users to download files stored in an asset. This is a two step process:
- Get file access information using the getFileAccessInfo API
- Use the information returned to access a specific file
Pre-requisites:
- One or more assets defined in MK.IO with content
- A personal access token, once can be generated in the user profile page of MK.IO (or via the tokens API)
- The name of the project in which the asset exists
- The name of the asset
- The path and name of the file to access
The following example uses the VSCode REST Client plugin to make an HTTP POST request to the getFileAccessInfo API:
@project = demo-library
@asset = privateOfferAcceptancePublic
###
# @name getFileAccessInfo
POST {{mkioBaseURL}}/api/v1/projects/{{project}}/media/assets/{{asset}}/getFileAccessInfo HTTP/1.1
Authorization: Bearer {{prod_token}}
The prod_token variable in the above is declared elsewhere, but is the personal access token mentioned in the pre-requisites.
The response will contain several fields which can be declared as variables:
###
@jwt = {{getFileAccessInfo.response.body.jwt}}
@url = {{getFileAccessInfo.response.body.url}}
@storageAccountName = {{getFileAccessInfo.response.body.storageAccountName}}
@containerName = {{getFileAccessInfo.response.body.containerName}}
Note that if you used a subpath of the asset to store content, this will also be returned in the body of the response and will need to be used in the file path of the following.
Get Files from Object Storage
The storageAccountName and containerName in above variables are then used in the body of a the request to the url appended by "/downloadBlob" with the jwt as the Authorization Bearer, thus:
###
# @name downloadBlob
POST {{url}}downloadBlob
Authorization: Bearer {{jwt}}
Content-Type: application/json
{
"storageAccountName": "{{storageAccountName}}",
"containerName": "{{containerName}}",
"fileName": "PrivateOfferAcceptance.mpd"
}