Update

async AsyncCogniteClient.files.update(
item: FileMetadata | FileMetadataWrite | FileMetadataUpdate | Sequence[FileMetadata | FileMetadataWrite | FileMetadataUpdate],
mode: Literal['replace_ignore_null', 'patch', 'replace'] = 'replace_ignore_null',
) FileMetadata | FileMetadataList

Update files.

Currently, a full replacement of labels on a file is not supported (only partial add/remove updates). See the example below on how to perform partial labels update.

Parameters:
  • item (FileMetadata | FileMetadataWrite | FileMetadataUpdate | Sequence[FileMetadata | FileMetadataWrite | FileMetadataUpdate]) – file(s) to update.

  • mode (Literal['replace_ignore_null', 'patch', 'replace']) – How to update data when a non-update object is given (FilesMetadata or -Write). If you use ‘replace_ignore_null’, only the fields you have set will be used to replace existing (default). Using ‘replace’ will additionally clear all the fields that are not specified by you. Last option, ‘patch’, will update only the fields you have set and for container-like fields such as metadata or labels, add the values to the existing. For more details, see Update and Upsert Mode Parameter.

Returns:

The updated files.

Return type:

FileMetadata | FileMetadataList

Examples

Update file metadata that you have fetched. This will perform a full update of the file metadata:

>>> from cognite.client import CogniteClient, AsyncCogniteClient
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> file_metadata = client.files.retrieve(id=1)
>>> file_metadata.description = "New description"
>>> res = client.files.update(file_metadata)

Perform a partial update on file metadata, updating the source and adding a new field to metadata:

>>> from cognite.client.data_classes import FileMetadataUpdate
>>> my_update = (
...     FileMetadataUpdate(id=1).source.set("new source").metadata.add({"key": "value"})
... )
>>> res = client.files.update(my_update)

Attach labels to a files:

>>> from cognite.client.data_classes import FileMetadataUpdate
>>> my_update = FileMetadataUpdate(id=1).labels.add(["PUMP", "VERIFIED"])
>>> res = client.files.update(my_update)

Detach a single label from a file:

>>> from cognite.client.data_classes import FileMetadataUpdate
>>> my_update = FileMetadataUpdate(id=1).labels.remove("PUMP")
>>> res = client.files.update(my_update)