CogniteFile in the core data model
CogniteFile uses theassets property to associate a file with one or more CogniteAssets, and other properties to hold metadata of the file.
The access control for CogniteFile is handled by the datamodelinstances access-control list (ACL). This is the only ACL required to access files in the core data model.
Working with files using the Python SDK
Create, retrieve and delete files
To create, retrieve, and delete files using the Python SDK:1
Create a file node
To create a file, use the Cognite Python SDK
CogniteFileApply data class:2
Retrieve the file node
3
Upload and download file content
4
Delete the file
Associate files to CogniteAsset
To associate files to CogniteAsset:1
Create or modify file with asset references
Provide the instance identifiers of the asset nodes:
2
Retrieve and verify asset references
Create and upload files using the API
You can ingest files represented with CogniteFile directly through the API. Create a file node in the Data Modeling Service, request an upload link, and upload the file contents. You’ll need to replace the placeholders in brackets{} used for the endpoint URLs and payload examples with appropriate values for your data model and files.
To create and upload files using the API:
1
Create an instance in the Data Modeling Service (DMS)
API documentation: Create or update nodes/edgesEndpoint URL: It’s important that you include a
https://{cdf_cluster}.cognitedata.com/api/v1/projects/{cdf_project_name}/models/instancesPayload example:source object mapping to the CogniteFile view in the list of sources in the payload. Without this, you’ll receive an error when requesting an upload link in the next step, because the instance won’t be able to be identified by the File service. If you’ve created a custom view extending CogniteFile that you want to target instead, however, replace the values for space, externalId and version in the source object with the corresponding values for your custom view:2
Request an upload file link
API documentation: Get upload file linkEndpoint URL:
https://{cdf_cluster}.cognitedata.com/api/v1/projects/{cdf_project_name}/files/uploadlinkPayload example:If you are uploading a file larger than 5 GiB you’ll need to request a Multipart file upload link instead.
3
Upload the file contents
Send a HTTP PUT request to the
uploadUrl (or uploadUrls if you’re using a multipart file upload link) in the response result from the previous query, with the relevant ‘Content-Type’ and ‘Content-Length’ headers according to the content of the file.Learn more: