Skip to content

Example C · Send a File

Send an encrypted file from the gateway — small files via relay, large files via QUIC when both peers support it.


Prerequisites

  • Gateway running with an active peer chat (Example B)
  • Active license
  • File available inside the container

Step 1 — Mount a data directory

docker run -d \
  --name privitty-edged \
  -e PRIVITTY_PROFILE=factory-gw-01 \
  -p 127.0.0.1:7200:7200 \
  -v privitty-data:/var/lib/privitty \
  -v /host/telemetry:/data:ro \
  privitty/edge:latest

Place your file on the host at /host/telemetry/report.csv — it appears inside the container as /data/report.csv.


Step 2 — Create a test file (optional)

echo "timestamp,value
2025-05-25T10:00:00,42.1
2025-05-25T10:01:00,43.5" > /host/telemetry/report.csv

Step 3 — Resolve peer contact ID

Assume chat ID 7 with the ops-center operator:

curl -s -X POST http://127.0.0.1:7200/rpc \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"get_chat_contacts","params":[1,7],"id":1}' | jq .
{"jsonrpc":"2.0","result":[1,12],"id":1}

Contact 1 is self; contact 12 is the peer.


Step 4 — Encrypt the file

curl -s -X POST http://127.0.0.1:7200/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc":"2.0",
    "method":"privitty_send_file",
    "params":[1,7,12,"/data/report.csv",true,false,1440],
    "id":2
  }' | jq .
Param Value Meaning
allow_download true Peer can save the decrypted file
allow_forward false Peer cannot forward
duration 1440 24-hour access window (minutes)

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "encrypted_path": "/data/report.csv.prv",
    "file_id": 42,
    "plaintext_hash": "…",
    "prv_file_hash": "…"
  },
  "id": 2
}

Step 5 — Deliver the encrypted attachment

curl -s -X POST http://127.0.0.1:7200/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc":"2.0",
    "method":"send_msg",
    "params":[1,7,{
      "text":"Daily telemetry report",
      "file":"/data/report.csv.prv",
      "viewtype":"File"
    }],
    "id":3
  }' | jq .

Transfer paths

File size Path Notes
Small (< ~1 MB) Relay (IMAP/SMTP) Encrypted .prv travels as a standard attachment
Large (≥ ~1 MB) QUIC (iroh P2P) Peer receives a QUIC offer; file transfers directly when both sides support it

The gateway handles path selection automatically. Your application makes the same two RPC calls regardless of size.

Monitor progress via SSE:

curl -N http://127.0.0.1:7200/events

Look for PrivittyFileEncrypted and MsgDelivered.


Step 6 — Revoke access (optional)

curl -s -X POST http://127.0.0.1:7200/rpc \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"privitty_revoke_file_access","params":[1,7,42,12],"id":4}'

See Curl Cookbook · Revoke.


Next