Skip to main content

CoreFileObject management tasks

upload_file_object

Uploads a file to an Infrahub CoreFileObject object.

Creates the object if it does not exist, or updates it if the file content has changed (SHA-1 checksum comparison). When the local content is identical to the one stored on the server the upload is skipped (idempotent).

Provide either file_path (to upload a file from disk) or content with file_name (to upload raw bytes).

Parameters

ParameterTypeRequiredDefaultDescription
taskTaskYesThe Nornir task instance containing host-related data.
kindstrYesThe schema kind that inherits from CoreFileObject.
file_pathstr | PathNoFilesystem path to the file to upload.
contentbytesNoRaw file content to upload. Requires file_name.
file_namestrNoFile name to associate with content. Ignored when file_path is used.
datadictNoAdditional object attributes to set on create or update.
object_idstrNoUUID of an existing object to update.
hfidlist[str]NoHFID components identifying an existing object.
branchstrNothe client's default branchTarget Infrahub branch. Defaults to the client's default branch.
**kwargsAnyNoExtra keyword arguments forwarded to client.create (e.g. allow_upsert, timeout).

Examples

Upload a contract PDF to a CoreFileObject object

from nornir_infrahub.plugins.tasks import upload_file_object

result = nr.run(
task=upload_file_object,
kind="NetworkCircuitContract",
file_path="/path/to/contract.pdf",
data={"contract_start": "2026-01-01"},
)

download_file_object

Downloads file content from an Infrahub CoreFileObject object.

Returns the file content as base64-encoded binary data, with a UTF-8 text representation for text MIME types. Optionally saves the file to a local path.

When save_to points to an existing file whose SHA-1 matches the server-side checksum, the download is skipped and changed is False (idempotent, similar to nornir_utils.plugins.tasks.files.write_file).

Parameters

ParameterTypeRequiredDefaultDescription
taskTaskYesThe Nornir task instance containing host-related data.
kindstrYesThe schema kind that inherits from CoreFileObject.
object_idstrNoUUID of the object to download from.
hfidlist[str]NoHFID components identifying the object.
save_tostr | PathNoLocal path where the downloaded file should be written. A directory receives the original file name; an explicit path is used as-is.
branchstrNothe client's default branchTarget Infrahub branch. Defaults to the client's default branch.

Examples

Download a file from a CoreFileObject object

from nornir_infrahub.plugins.tasks import download_file_object

result = nr.run(
task=download_file_object,
kind="NetworkCircuitContract",
hfid=["contract-2026"],
)