Elements runtime reference / Request artifacts

readFile

Read a request-scoped Element artifact file visible to the current run.

Signatuur

readFile(path, bucket=None, prefix=None, encoding='utf-8', asBytes=False, maxBytes=None, withMetadata=False)

Doel

Read a request-scoped Element artifact file visible to the current run.

Aliases and imports

  • read_file
  • files.read
  • files.read_file

Payloadformaat

Use these fields as the Python call arguments or keyword payload for this helper.

{
  "path": "exports/preview.json",
  "encoding": "utf-8",
  "withMetadata": true
}
FieldDescription
pathRelative artifact path or worker-returned artifact reference visible to the current run.
bucket/prefixOptional worker-controlled artifact bucket/prefix override.
encodingText encoding used when asBytes is false.
asBytesWhen true, return metadata with base64 data instead of decoded text.
maxBytesOptional read cap bounded by the worker.
withMetadataWhen true, return the full metadata envelope even for text reads.

Return payload

{
  "path": "exports/preview.json",
  "contentType": "application/json",
  "encoding": "utf-8",
  "text": "{\"title\":\"Preview\"}",
  "size": 19
}

Voorbeeld

def run():
    metadata = files.read("exports/preview.json", withMetadata=True)
    return {"text": metadata["text"]}

Scope-notities