Post a story with a file
Upload a file to get a token, then create a story that uses the file as its main asset.
Adding a file to a story takes two steps. You upload the file first and receive a token. Then you create the story and reference the token in its assets.
Upload the file
Post the file's bytes to the upload address, with the same bearer token you use for the API:
curl --request POST \
--data-binary @./version1.pdf \
--header "Authorization: Bearer kp-oauth2-AXLmAPDkbuEGt7oWaza60N5cFw9i" \
--header "Content-Type: application/octet-stream" \
--header "Content-Disposition: attachment; filename=version1.pdf" \
https://your-platform-name.elium.com/api/upload/file
The response is a JSON document with the token that identifies the uploaded file. It also carries the file's name, MIME type and a thumbnail address, left out here; only the token is needed:
{
"file": {
"token": ".eJw...xMWA"
},
"success": true
}
Create the story with the file
In the variables, reference the token in assets, together with a universally unique identifier (UUID) that you generate yourself. The same UUID in mainAsset makes the file the main asset of the story.
The mutation:
mutation storyPostExample($input: StoryPostInput!) {
storyPost(input: $input) {
story {
slug
version {
title
mainAsset {
__typename
... on FileAsset {
downloadUrl
embed
mimetype
filesize
}
}
}
}
}
}
The variables:
{
"input": {
"assets": [
{
"type": "FILE",
"file": ".eJw...xMWA",
"uuid": "GENERATED_UUID"
}
],
"mainAsset": "GENERATED_UUID",
"publish": true,
"spaceId": "SPACE_ID",
"title": "My story with a file as main asset"
}
}
The response describes the new main asset (the embed object is shortened here):
{
"data": {
"storyPost": {
"story": {
"slug": 278,
"version": {
"title": "My story with a file as main asset",
"mainAsset": {
"__typename": "FileAsset",
"downloadUrl": "https://your-platform-name.elium.com/api/story/asset/278/download/95/version1.pdf",
"embed": {
"url": "https://your-platform-name.elium.com/api/story/asset/278/download/95/version1.pdf",
"thumbnail_url": "https://your-platform-name.elium.com/api/story/asset/278/thumbnail/95?fallback=false&tclass=xxlarge",
"cover_url": "https://your-platform-name.elium.com/api/story/asset/278/thumbnail/95?fallback=false&tclass=cover",
"filename": "version1.pdf",
"filesize": 1191622,
"mimetype": "application/pdf",
"digest": "9bfd53912a4364ad1ff99e45a70860eda0f64ae13f04d568d24e0d45f67b0c6a"
},
"mimetype": "application/pdf",
"filesize": 1191622
}
}
}
}
}
}
A file that is not the main asset goes in assets the same way, without mainAsset. To show it in the body, reference its UUID with the <el-asset> element described in Markdown input format.