Tutorial 9 of 18

How to Handle Large Messages with Chunking

Understand how DNotifier splits large payloads into chunks, reassembles them before delivery, and applies plan-based size limits.

7 min read

DNotifier SDKs automatically split payloads larger than your plan's per-chunk limit and reassemble them on the receiver before onMessage fires. You send one logical message; recipients always see the complete payload.

How Chunking Works

send(large payload)
       │
       ▼
SDK compares size to messageSizeLimit
       │
       ├── fits in one chunk → single frame
       │
       └── too large → split into N chunks
                  │
                  ▼
            each chunk framed with metadata
            (packet index, total count, message id)
                  │
                  ▼
            receiver SDK buffers chunks
                  │
                  ▼
            all N received → merge → onMessage(complete payload)

messageSizeLimit

After connect(), read the limit from the client:

JavaScript

await notifier.connect();
console.log(notifier.messageSizeLimit); // bytes, from your plan

Dart

await notifier.connect();
print(notifier.messageSizeLimit);

This value is also available via getPlanLimits(). It defines the maximum size of each chunk, not necessarily the total message size — multi-chunk messages can exceed this limit in total.

What Gets Chunked

APIChunked automatically
send() with large data.content (images, docs)Yes
sendBinary() with large bufferYes
Small text messagesNo — sent in a single frame

Receiver Behavior

Your onMessage handler always receives a complete reassembled message:

onMessage: (msg) => {
  // This fires only after all chunks arrive
  const body = msg.payload.toJSON();
  // body.content is the full image bytes, not a partial chunk
},

If the connection drops mid-chunk, the partial buffer is discarded. The sender may retry after reconnect.

Best Practices

  • Check limits at connect — gate file uploads in the UI when files exceed reasonable bounds.
  • Show upload progress locally — DNotifier does not expose per-chunk send progress, so track file reading and upload state in your app.
  • Prefer structured send() for media — chunking, history, and typed handlers work together.
  • Compress before sending — reduce the chunk count for very large payloads when your format allows.

Plan Relationship

Message volume and size limits count toward your plan quotas. See the Plan limits & quotas and Pricing & plans documentation for details.