Working with Attachments

How files are stored

When an attachment is uploaded to a form, it is uploaded to a filestore, and a reference to that file is stored in the attachment field. When the attachment is returned via the API as part of the values from the submission, it looks something like this:

     "Attachments": [
    {
      "contentType": "image/png",
      "link": "/space-slug/submissions/8f0feb79-fd56-11e8-aca1-852d4a633f0e/files/Attachments/0/image.png",
      "name": "image.png",
      "size": 12426
    }
  ]

How to access files

The data stored in the submission contains the content type, the file name, and a link to the file in Kinetic Agent. This link is not ideal for downloadable files. Instead, the following API endpoint is designed for downloading attachments from a submission: /submissions/{submissionId}/files/{fieldName}/{fileIndex}/{fileName}/url.

To download a file, you'll need the submission ID, the field name, the file name, and the file index. In the example above, the file index is 0. This endpoint will give you a valid link for downloading the file for 5 seconds. This time-of-expiring link is used when the user clicks on an attachment in the UI (for example, in the clone attachment handler when the attachment is retrieved to copy).

How not to use attachments

Because files are always referenced with these expiring URLs, they are never cached by the client. This means that submissions are not good places to store images to be used in the theme or in any other way repeatedly loaded by the user's browser.