Create a Document¶
To work with a document, SEAL Operator has to have access to the document. This means that the document has to be available in the repository of an installed service such as the operator-fileupload
service.
Unless the document exist in a repository, it has to be created and uploaded:
- Create the document item and specify the metadata
- Upload the binary file
Documents are created in a repository by a POST request to the repository endpoint. The request body contains the properties and metadata as described in Documents. The result will be the document including administrative properties such as the ID and the href URL.
Create a document in the root folder of a repository:
Example - endpoint URL for creating a document in the operator-fileupload
service
/v1/services/operator-fileupload/repo/
Create a document located in an already existent collection (similar to a subdirectory):
Example - endpoint URL for creating a document in the collection with the ID collectionID
in the operator-fileupload
service
/v1/services/operator-fileupload/repo/<collectionId>
For updating the binary content for the document, the returned document ID is used in a PUT request with HTTP content type (Content-Type
) application/octet-stream
to the documents content endpoint.
Example - endpoint URL for the content of a document with the ID docId
/v1/services/operator-fileupload/repo/<docId>/content
The result will be the HTTP status code 204 without a response body.
Code Examples¶
Bash¶
#!/bin/bash
# !Assuming $TOKEN contains a valid JWT access token!
AUTH="Authorization: Bearer $TOKEN"
JSON="Content-Type:application/json"
BINARY="Content-Type:application/octet-stream"
# create document in root
DOC=$(jq -c -n '{
"name":"hello.txt",
"type":"document",
"metadata": {
"description": "Hello World Example"
}
}')
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$DOC" "https://localhost:3008/v1/services/operator-fileupload/repo")
ID=$(echo "$RES" | jq -r '.uuid')
HREF=$(echo "$RES" | jq -r '.links.self.href')
echo "Created document with id $ID and href $HREF"
# add content to document
echo "Hello World" >hello.txt
curl -k -X PUT -H "$AUTH" -H "$BINARY" -d "@./hello.txt" "https://localhost:3008/v1/services/operator-fileupload/repo/$ID/content"
JavaScript¶
'use strict';
const request = require('request-promise-native');
const createDocument = async function(token) {
// create document in root
let req = {
url: 'https://localhost:3008/v1/services/operator-fileupload/repo',
headers: {
Authorization: `Bearer ${token}`
},
body: {
name: 'hello.txt',
type: 'document',
metadata: {
description: 'Hello World Example'
}
},
resolveWithFullResponse: true,
json: true,
strictSSL: false
};
const res = await request.post(req);
const id = res.body.uuid;
const href = res.body.links.self.href;
console.log(`Created document with id ${id} and href ${href}`);
// add content to document
req = {
url: `https://localhost:3008/v1/services/operator-fileupload/repo/${id}/content`,
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/octet-stream'
},
body: 'Hello World',
resolveWithFullResponse: true,
strictSSL: false
}
await request.put(req);
};