Skip to content

Files API Reference ​

Files are uploaded to and retrieved from a lab. Use the lab code returned by the Labs API as {$VIMI_LAB} in each request.

Get all Files ​

GET - api/v1/lab/{$VIMI_LAB}/files

Returns all active files owned by the API user or shared with the lab. File content is not included in the list.

The following query parameters can be used to filter the list:

  • filetype - Image, Dataset, Video, Code, or Document
  • mime_type - MIME type such as text/plain or image/png; URL-encode the value when necessary

Example: api/v1/lab/{$VIMI_LAB}/files?filetype=Dataset&mime_type=text%2Fplain

Response ​

json
{
    "links": {
        "self": "https://{$VIMI_BASE_URL}/api/v1/lab/vimi/files"
    },
    "data": [
        {
            "type": "files",
            "id": "1234",
            "attributes": {
                "name": "new-species.csv",
                "label": "Panthera example observations",
                "comment": "Population observations for a newly identified species.",
                "file_type": "Dataset",
                "size": 36,
                "owner_id": 123,
                "topic_id": 42,
                "topic_name": "Population studies",
                "shared_with_lab": true,
                "source": "API Upload",
                "status": "Ready",
                "created_at": "2000-01-01T00:00:00.000000Z",
                "updated_at": "2000-01-01T00:00:00.000000Z",
                "metadata": {
                    "Binomial Nomenclature": {
                        "label": "Binomial Nomenclature",
                        "value": "Panthera example"
                    },
                    "Physical Description": {
                        "label": "Physical Description",
                        "value": "Large cat with a dark spotted coat."
                    },
                    "Phylum": {
                        "label": "Phylum",
                        "value": "p2"
                    },
                    "Population Estimates": {
                        "label": "Population Estimates",
                        "value": 3200
                    }
                },
                "metadata_form_id": 999,
                "metadata_form_revision": 1,
                "metadata_validation": "validated"
            },
            "links": {
                "self": "https://{$VIMI_BASE_URL}/api/v1/lab/vimi/files/1234",
                "download": "https://{$VIMI_BASE_URL}/api/v1/lab/vimi/files/1234/download"
            }
        }
    ]
}

Attributes:

  • name - stored file name, including its extension
  • label - user-facing name of the file
  • comment - description or notes about the file
  • file_type - Image, Dataset, Video, Code, or Document
  • size - file size in bytes
  • owner_id - ID of the user who owns the file
  • topic_id - ID of the topic or subtopic the file belongs to, or null when uncategorized
  • topic_name - readable name of that topic, or null when uncategorized
  • shared_with_lab - whether other lab members can access the file
  • source - how the file was added; files created with this API use API Upload
  • status - current processing status
  • created_at - timestamp of creation
  • updated_at - timestamp of last update
  • metadata - labelled metadata stored with the file
  • metadata_form_id - ID of the form used to validate the metadata, or null
  • metadata_form_revision - revision number of the form used to validate the metadata, or null
  • metadata_validation - validated, unvalidated, or null

Upload a File ​

POST - api/v1/lab/{$VIMI_LAB}/files

Uploads a file and returns the created file resource.

Text content can be sent directly. Binary content must be Base64-encoded and sent with "content_encoding": "base64".

Request ​

json
{
    "name": "new-species.csv",
    "label": "Panthera example observations",
    "content": "location,count\nBritish Columbia,3200",
    "file_type": "Dataset",
    "shared_with_lab": true,
    "form_id": 999,
    "metadata": {
        "Binomial Nomenclature": {
            "value": "Panthera example"
        },
        "Physical Description": {
            "value": "Large cat with a dark spotted coat."
        },
        "Phylum": {
            "value": "p2"
        },
        "Population Estimates": {
            "value": 3200
        }
    },
    "file_has_header": true,
    "comment": "Population observations for a newly identified species."
}
json
{
    "name": "new-species.csv",
    "label": "Panthera example observations",
    "content": "location,count\nBritish Columbia,3200",
    "file_type": "Dataset",
    "shared_with_lab": true,
    "form_id": 999,
    "metadata": {
        "Binomial Nomenclature": "Panthera example",
        "Physical Description": "Large cat with a dark spotted coat.",
        "Phylum": "p2",
        "Population Estimates": 3200
    },
    "file_has_header": true,
    "comment": "Population observations for a newly identified species."
}

Request attributes:

  • name - required file name, including its extension
  • label - required unless the form generates it
  • content - required file content as text or a Base64 string
  • content_encoding - optional raw or base64; content is treated as raw when omitted
  • file_type - optional Image, Dataset, Video, Code, or Document; inferred from name when omitted
  • shared_with_lab - optional whether other lab members can access the file; defaults to false when no form is used. With a form, the form's lab-sharing policy can force or default this value
  • form_id - optional ID of an active form used to validate metadata; the form's active revision is used
  • metadata_form_revision_id - optional pins a specific form revision, including published or retired revisions; takes precedence over form_id
  • topic - optional ID of the topic or subtopic to store the file under; must belong to the lab and be accessible to the API user. Use the Topics API to discover IDs. When omitted, the form's field is used, then the user's active field, otherwise the file is stored as uncategorized
  • metadata - optional metadata values as a JSON object
  • tag - optional tag assigned to the file
  • comment - optional description or notes about the file
  • file_has_header - optional whether the first row of a dataset is a header
  • header - optional explicit dataset header
  • contributor - optional contributor recorded on the dataset
  • classification - optional classification recorded on the dataset
  • header_mask - optional dataset header mask
  • header_default - optional default dataset header
  • plots - optional array of chart IDs to attach to the dataset

contributor, classification, header_mask, header_default, and plots apply only to dataset uploads. They are ignored for other file types.

Use the Topics API to discover topic IDs.

When form_id or metadata_form_revision_id is provided, the metadata is validated against that revision, form defaults are applied, and the form configuration controls upload naming:

  • a compatible form requires the resolved file type to be listed in the revision's file_types; otherwise the upload is rejected with 422
  • when topic is provided and the form has a field_id, the topic must be that field or one of its descendants; otherwise the upload is rejected with 422
  • the form may automatically generate and override the stored file name
  • the form may automatically generate and override the label; when it does, label may be omitted, otherwise label is required
  • uploadPath creates missing nested topics under the selected topic, and the file is stored in the deepest topic

metadata_form_revision_id pins a specific revision even when the form has a newer active revision. Without it, form_id uses the form's active revision.

Without a form, metadata can contain any fields and is marked as unvalidated. A value can be sent directly or in the labelled shape returned by the Forms API:

json
{
    "metadata": {
        "temperature_c": 21.7,
        "device_serial": {
            "label": "Device serial",
            "value": "sensor-213"
        }
    }
}

Response ​

Status: 201 Created

json
{
    "data": {
        "type": "files",
        "id": "1234",
        "attributes": {
            "name": "new-species.csv",
            "label": "Panthera example observations",
            "comment": "Population observations for a newly identified species.",
            "file_type": "Dataset",
            "size": 36,
            "owner_id": 123,
            "topic_id": 42,
            "topic_name": "Population studies",
            "shared_with_lab": true,
            "source": "API Upload",
            "status": "Ready",
            "created_at": "2000-01-01T00:00:00.000000Z",
            "updated_at": "2000-01-01T00:00:00.000000Z",
            "metadata": {
                "Binomial Nomenclature": {
                    "label": "Binomial Nomenclature",
                    "value": "Panthera example"
                },
                "Physical Description": {
                    "label": "Physical Description",
                    "value": "Large cat with a dark spotted coat."
                },
                "Phylum": {
                    "label": "Phylum",
                    "value": "p2"
                },
                "Population Estimates": {
                    "label": "Population Estimates",
                    "value": 3200
                }
            },
            "metadata_form_id": 999,
            "metadata_form_revision": 1,
            "metadata_validation": "validated",
            "content": "location,count\nBritish Columbia,3200"
        }
    },
    "links": {
        "self": "https://{$VIMI_BASE_URL}/api/v1/lab/vimi/files/1234",
        "download": "https://{$VIMI_BASE_URL}/api/v1/lab/vimi/files/1234/download"
    }
}

Get a File ​

GET - api/v1/lab/{$VIMI_LAB}/files/{file_id}

Returns a file owned by the API user or shared with the lab. The response has the same structure as Upload a File.

The content attribute is included when the file is no larger than 2 MiB. Text content is returned directly, JSON content is returned as parsed JSON, and binary content is returned as a Base64 string. Use the download endpoint for larger files.

Download a File ​

GET - api/v1/lab/{$VIMI_LAB}/files/{file_id}/download

Downloads the original file as an attachment.

Delete a File ​

DELETE - api/v1/lab/{$VIMI_LAB}/files/{file_id}

Deletes a file owned by the API user. A file shared with the lab cannot be deleted by another lab member.

Response ​

Status: 204 No Content