Uploading content

You can upload content by issuing a multi-part form POST.

  • the GraphQL mutation
  • the accompanying file upload part or parts.
The uploaded data is specified by setting the value of a “content” field in the mutation using a GraphQL variable. The variable name itself maps to a part in the multi-part form that holds an uploaded file.
If there is only one content element in the document, it can be specified using the content field of the documentProperties argument. The following example shows what the mutation might look like:
mutation ($contvar:String) {
  createDocument(
    repositoryIdentifier:"OS1" 
    fileInFolderIdentifier: "/Folder for Browsing" 
    documentProperties: {
      name: "Doc with Content" 
      content:$contvar
    } 
    checkinAction: {} 
  ) 
  { 
    id 
    name 
  } 
}

The document contentType in the previous example will be whatever mime type is submitted in the file part of the multi-part form.

This example shows how this mutation and corresponding file upload and the variable itself might be passed using a curl command. The variable values can be null because it is the variable name itself that maps to the part in the multi-part form.
curl localhost:8080/graphql -F graphql='{"query":"mutation ($contvar:String) {createDocument(repositoryIdentifier:\"OS1\" fileInFolderIdentifier: \"/Folder for Browsing\" documentProperties: {name: \"Doc with Content\" content:$contvar} checkinAction: {} ) { id name } }", "variables":{"contvar":null} }' -F contvar=@test.txt

Multiple content elements with uploaded content (ContentTransfer) as well as references to content (ContentReference) can be updated using the contentElements field of the documentProperties argument.

The following example shows what the mutation might look like, still with only a single content element (although it might contain multiple elements):
mutation ($contvar:String) {
  createDocument(
    repositoryIdentifier:"OS1" 
    fileInFolderIdentifier: "/Folder for Browsing" 
    documentProperties: {
      name: "Doc with Content" 
      contentElements:{
        replace: [
          {
            type: CONTENT_TRANSFER 
            contentType: "text/plain" 
            subContentTransfer: {
              content:$contvar
            } 
          }
        ]
      } 
    } 
    checkinAction: {} 
  ) 
  { 
    id 
    name 
  } 
}

The previous example allows caller to explicitly specify contentType that will overwrite the mime type submitted in the file part of the multi-part form.

The following example shows how this mutation might be specified using a curl command:
curl localhost:8080/graphql -F graphql='{"query":"mutation ($contvar:String) {createDocument(repositoryIdentifier:\"OS1\" fileInFolderIdentifier: \"/Folder for Browsing\" documentProperties: {name: \"Doc with Content\" contentElements:{replace: [{type: CONTENT_TRANSFER contentType: \"text/plain\" subContentTransfer: {content:$contvar} }]} } checkinAction: {} ) { id name } }", "variables":{"contvar":null} }' -F contvar=@test.txt