files_streaming()
Streams a document’s files chunk-by-chunk directly off the still-open connection — without buffering the whole file in memory or in a temporary file. The counterpart to
files(), intended for large documents that should be forwarded (e.g. to an HTTP
response or another file) without local caching. The current files are retrieved via
std.StoreInCacheById.
files_streaming() is a context manager: the (pooled) connection stays borrowed for
the lifetime of the with block. On exit the connection is handled safely (see
Connection lifecycle).
|
The job’s response parameters, errors and |
1. Signature
-
Sync
-
Async
with ecm.dms.files_streaming(
model: ECMDocumentModel | int,
*,
flags: int = 1,
convert: StoreInCacheByIdConversion = StoreInCacheByIdConversion.NONE,
when_cold_then_tiff: bool = False,
add_annotations: bool = False,
) as response: # JobStreamingResponse
...
async with ecm.dms.files_streaming(
model: ECMDocumentModel | int,
*,
flags: int = 1,
convert: StoreInCacheByIdConversion = StoreInCacheByIdConversion.NONE,
when_cold_then_tiff: bool = False,
add_annotations: bool = False,
) as response: # AsyncJobStreamingResponse
...
2. Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
|
|
— |
The document: either an |
|
|
|
Transfer flags: |
|
|
|
Optional conversion applied before transfer (see files()). |
|
|
|
If |
|
|
|
If |
|
Unlike |
3. Return value
The context manager yields a JobStreamingResponse (sync) or
AsyncJobStreamingResponse (async).
| Member | Description |
|---|---|
|
Server return code of the job ( |
|
Typed access to a response parameter (like |
|
List of |
|
Iterator over the response files as |
|
Marks the response as deliberately abandoned (no |
| Member | Description |
|---|---|
|
File metadata, known before the first chunk. |
|
Iterator over the file bytes in chunks (default 64 KiB). Updates the running SHA-1 digest and reads the file footer at the end. |
|
Deliberately discards this file (like |
4. Connection lifecycle
The with / async with block always protects the connection:
-
Fully consumed → the trailing SHA-1 digest is validated and the connection returns to the pool.
-
Accidentally partial → the connection is invalidated (socket closed) and an
IncompleteStreamErroris raised (unless the block is already unwinding another exception, which takes precedence). -
Deliberately aborted via
response.abort()/file.skip()→ the connection is invalidated, no error.
5. Examples
5.1. Stream a document to a file
-
Sync
-
Async
with ecm.dms.files_streaming(document) as response:
assert response.return_code == 0
for attachment in response.iter_files():
with open(attachment.name, "wb") as out:
for chunk in attachment.iter_chunks():
out.write(chunk) # no RAM/temp buffer
async with ecm.dms.files_streaming(document) as response:
async for attachment in response.iter_files():
with open(attachment.name, "wb") as out:
async for chunk in attachment.iter_chunks():
out.write(chunk)
6. Comparison with files() and document_stream()
| Aspect | files() |
document_stream() |
files_streaming() |
|---|---|---|---|
Result type |
List of |
|
|
Buffering |
RAM or temp file |
RAM (the read range) |
None — straight off the socket |
Multiple files |
Yes |
No |
Yes (file-by-file) |
Server job |
|
|
|
7. See also
-
files() — Load complete files buffered
-
document_stream() — Read a byte range of a file
-
digest() — Retrieve a document’s hash value