Upload

Uploading a document is a 2-step process:

  1. Request to upload a document or revision via the api
  2. Use the returned details along with your file in a multipart/form-data HTTP POST request

Request an upload

Content can be uploaded as new documents, or as an updated revision of an existing document.

New document

The following mutation requests the upload of a new document, providing the basic metadata:

Example

mutation{
  documents{
    requestUpload(input:{
      folderId: "Rm9sZGVyOjk2NA=="
      name: "Survery results"
      description: "Results of the latest survey"
      fileName: "survey-results.pdf"
      contentType: "application/pdf"
    }) {
      uploadDetails{
        payload
        url
      }
      document{
        id 
      }
      errors{
        label
        message 
        value
      }
    }
  }
}

For the full range of available upload parameters see our DocumentUploadInput API Reference.

The response returns the uploadDetails necessary for the following step:

{
  "data": {
    "documents": {
      "requestUpload": {
        "uploadDetails": {
          "payload": "{ \"key1\":\"value1\", \"key2\":\"value2\" }",
          "url": "https://upload.example.com"
        },
        "document": {
          "id": "RE1TRG9jdW1lbnQ6OQ=="
        },
        "errors": []
      }
    }
  }
}

Existing document

A very similar mutation allows uploading a new revision for an existing document

Example

mutation{
  documents{
    requestUploadRevision(input:{
      documentId: "RE1TRG9jdW1lbnQ6OQ=="
      fileName: "survey-results-updated.pdf"
      contentType: "application/pdf"
    }) {
      uploadDetails{
        payload
        url
      }
      document{
        id 
      }
      errors{
        label
        message 
        value
      }
    }
  }
}

The response contains the same uploadDetails returned by the requestUpload mutation from the previous example.

Perform the upload

The uploadDetails returned in the previous response must be supplied in the body of a HTTP POST request with multipart/form-data (see specification):

  1. prepare a POST request to the given url
  2. extract the key/value pairs in payload as the form data part
  3. include the file contents as the second content part

Using cURL

curl -v
     [-F key=value for each key-value pair in uploadDetails.payload]
     -F file=@[filepath]
     [uploadDetails.url]

Using Javascript

See documentation on multipart/form-data requests.