Appearance
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, orDocumentmime_type- MIME type such astext/plainorimage/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 extensionlabel- user-facing name of the filecomment- description or notes about the filefile_type-Image,Dataset,Video,Code, orDocumentsize- file size in bytesowner_id- ID of the user who owns the filetopic_id- ID of the topic or subtopic the file belongs to, ornullwhen uncategorizedtopic_name- readable name of that topic, ornullwhen uncategorizedshared_with_lab- whether other lab members can access the filesource- how the file was added; files created with this API useAPI Uploadstatus- current processing statuscreated_at- timestamp of creationupdated_at- timestamp of last updatemetadata- labelled metadata stored with the filemetadata_form_id- ID of the form used to validate the metadata, ornullmetadata_form_revision- revision number of the form used to validate the metadata, ornullmetadata_validation-validated,unvalidated, ornull
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 extensionlabel- required unless the form generates itcontent- required file content as text or a Base64 stringcontent_encoding- optionalraworbase64; content is treated as raw when omittedfile_type- optionalImage,Dataset,Video,Code, orDocument; inferred fromnamewhen omittedshared_with_lab- optional whether other lab members can access the file; defaults tofalsewhen no form is used. With a form, the form's lab-sharing policy can force or default this valueform_id- optional ID of an active form used to validatemetadata; the form's active revision is usedmetadata_form_revision_id- optional pins a specific form revision, includingpublishedorretiredrevisions; takes precedence overform_idtopic- 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 uncategorizedmetadata- optional metadata values as a JSON objecttag- optional tag assigned to the filecomment- optional description or notes about the filefile_has_header- optional whether the first row of a dataset is a headerheader- optional explicit dataset headercontributor- optional contributor recorded on the datasetclassification- optional classification recorded on the datasetheader_mask- optional dataset header maskheader_default- optional default dataset headerplots- 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 with422 - when
topicis provided and the form has afield_id, the topic must be that field or one of its descendants; otherwise the upload is rejected with422 - the form may automatically generate and override the stored file name
- the form may automatically generate and override the label; when it does,
labelmay be omitted, otherwiselabelis required uploadPathcreates 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
