Skip to main content
The MediaReupload struct provides a method to request the server to re-upload media when the original CDN URL has expired. This is essential for long-running bots that need to download media from older messages.

Access

Access media reupload operations through the client:

Methods

request

Request the server to re-upload media for a message with an expired URL.
&MediaReuploadRequest
required
Parameters identifying the media message to re-upload.
MediaRetryResult
The result of the reupload request. On success, contains a new direct_path for downloading.
Example:

request_many

Request re-upload for several messages at once, concurrently. Use this for bulk recovery — e.g. resuming a client after a long offline period leaves many expired media URLs — since it completes in roughly one request timeout instead of the serial sum of per-item waits.
&[MediaReuploadRequest]
required
The batch of reupload requests.
Vec<Result<MediaRetryResult, MediaReuploadError>>
One result per input request, in the same order as reqs. One item failing does not abort the others.
Example:
Duplicate msg_ids within one batch are rejected (past the first occurrence) with MediaReuploadError::InvalidRequest — the underlying mediaretry waiter is keyed on message id alone, so two in-flight waiters for the same id could otherwise resolve each other with the wrong payload. A message id is unique per message, so a duplicate in a batch is a caller mistake.

Protocol flow

  1. The client encrypts a ServerErrorReceipt protobuf using an HKDF-derived key from the media key
  2. A <receipt type="server-error"> stanza is sent with the encrypted payload and <rmr> metadata
  3. The client waits up to 30 seconds for a <notification type="mediaretry"> response
  4. The response is decrypted and the new directPath is extracted

Types

MediaReuploadRequest

MediaRetryResult

Error handling

The method returns Result<MediaRetryResult, MediaReuploadError>. The MediaRetryResult enum itself distinguishes between server-side success and failure; MediaReuploadError covers transport and validation failures:
  • Client — wraps ClientError (transport/client-layer failures)
  • NotLoggedIn — Cannot determine own JID
  • InvalidRequest — Newsletter messages are not supported for media reupload; or, when using request_many, a msg_id appears more than once in the batch
  • Timeout — The server did not respond within 30 seconds
  • Internal — Encryption failure or other internal error
Media reupload requests have a 30-second timeout. If the server does not respond in time, the request fails with a timeout error.
Media reupload is not supported for newsletter messages. Newsletter messages do not have media keys, so the encrypted retry protocol cannot be used.

See also