Some drivers expose binary data streams in addition to discrete addresses — typically file transfer protocols (FTP, …). The /peers/gateways/{id}/streaming endpoint exposes these streams over plain HTTP, so any client can upload or download a file without learning the driver's wire protocol.
This endpoint maps directly onto two driver methods:
readStream(address, socketName, options, callback) — invoked by GETwriteStream(address, socketName, options, callback) — invoked by POSTDrivers that do not implement these methods return 500 when called.
| Driver | Download (GET) |
Upload (POST) |
Address |
|---|---|---|---|
| FTP | yes | yes | %ftp (base directory) or %ftp/<path>; a directory is transferred as a TAR archive (ZIP with options.zip) |
| CSV export | yes | no (read only) |
%csv_file/<file name>, or %csv_file/last.csv for the latest file |
| Azure IoT | no | yes | %azure:file_upload (file name in options.name) |
Other drivers answer 500 with method not found. For FTP, see also FTP driver, 3.5 File transfer (streaming).
GET /peers/gateways/{gatewayId}/streaming?address={addr}&fileName={name}&options={json}
POST /peers/gateways/{gatewayId}/streaming?address={addr}&fileName={name}&options={json}
| Segment | Description |
|---|---|
gatewayId |
Numeric id of a configured gateway |
| Query parameter | Description |
|---|---|
address |
The address (or path) to read from / write to on the driver — semantics depend on the driver |
fileName |
Optional. Filename advertised in the Content-Disposition header on download. Defaults to fileName |
options |
Optional. JSON-encoded object passed verbatim to the driver. Driver-specific |
address is the name of the address on the gateway, for example %ftp/exports/report.csv. In a URL, write the % as %25.
GET)The gateway opens a stream to the driver, sets the appropriate headers, and pipes the bytes directly to the response.
Response headers:
Content-Disposition: attachment; filename=<fileName>
Content-Type: application/octet-stream
Content-Length: <size, when the driver knows it in advance>
If the driver knows the file size up front, it is sent as Content-Length. Otherwise the response uses chunked transfer encoding and ends when the driver closes the stream.
Example — download a file from an FTP gateway:
curl -b cookies.txt -OJ \
'https://gateway.example.com/peers/gateways/3/streaming?address=%25ftp/exports/report.csv&fileName=report.csv'
The -OJ flags tell curl to use the filename from the Content-Disposition header.
Example — pipe directly into another tool:
curl -b cookies.txt -s \
'https://gateway.example.com/peers/gateways/3/streaming?address=%25ftp/data/dump.bin' \
| gzip > dump.bin.gz
POST)POST to the same URL with the file as the request body. The gateway opens a write stream on the driver and pipes the request body straight through.
Request:
POST /peers/gateways/3/streaming?address=%25ftp/uploads/firmware.bin
Content-Type: application/octet-stream
Content-Length: 1048576
<raw bytes>
The Content-Length header is forwarded to the driver as the bytes field of options, which lets some drivers preallocate or display upload progress.
Response:
200 OK with no body on success, 500 on failure.
Uploading needs the same right as writing a value: without it the answer is 403.
Example — upload a file to an FTP gateway:
curl -b cookies.txt -X POST \
-H 'Content-Type: application/octet-stream' \
--data-binary @firmware.bin \
'https://gateway.example.com/peers/gateways/3/streaming?address=%25ftp/uploads/firmware.bin'
The options parameter is a JSON object passed to the driver. The keys that drivers read:
| Driver | Direction | Key | Effect |
|---|---|---|---|
| FTP | upload | override |
true to replace an existing file. Without it, uploading to an existing file fails with file exists. |
| FTP | download and upload | zip |
true to transfer a directory as a ZIP archive instead of a TAR archive. |
| FTP | upload | bytes |
Set automatically from Content-Length. |
| Azure IoT | upload | name |
Name of the uploaded file (address %azure:file_upload). |
Example: replace a file on the FTP server (options={"override":true}):
curl -b cookies.txt -X POST -H 'Content-Type: application/octet-stream' \
--data-binary @report.csv \
'https://gateway.example.com/peers/gateways/3/streaming?address=%25ftp/exports/report.csv&options=%7B%22override%22%3Atrue%7D'
Stream errors are reported as a 500 response with the error message as plain text: driver not connected (gateway stopped), method not found (no streams on this driver), not streamable (address not supported), file not found, file exists (upload without override), busy (a transfer is already running on this address), not connected (FTP server not reachable). Azure IoT answers not a streamable address for any address other than %azure:file_upload.
For partial transfers (the connection was already streaming when the error happened), the gateway closes the stream early. Clients should treat a truncated download as a failure unless they have an out-of-band way to verify integrity (size, checksum).
The /peers/* dispatcher is designed for discrete RPC calls with JSON arguments and JSON responses — it does not handle binary payloads efficiently. The /streaming endpoint exists specifically for binary data:
| Use case | Best choice |
|---|---|
| Read/write a value | /peers/{peer}/{module}/{method} |
| Transfer a file or large binary blob | /peers/gateways/{id}/streaming |
| Retrieve driver diagnostic logs | /peers/{driver}/{id}/logs_* |