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.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.Protocol flow
- The client encrypts a
ServerErrorReceiptprotobuf using an HKDF-derived key from the media key - A
<receipt type="server-error">stanza is sent with the encrypted payload and<rmr>metadata - The client waits up to 30 seconds for a
<notification type="mediaretry">response - The response is decrypted and the new
directPathis extracted
Types
MediaReuploadRequest
MediaRetryResult
Error handling
The method returnsResult<MediaRetryResult, MediaReuploadError>. The MediaRetryResult enum itself distinguishes between server-side success and failure; MediaReuploadError covers transport and validation failures:
Client— wrapsClientError(transport/client-layer failures)NotLoggedIn— Cannot determine own JIDInvalidRequest— Newsletter messages are not supported for media reupload; or, when usingrequest_many, amsg_idappears more than once in the batchTimeout— The server did not respond within 30 secondsInternal— 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.
See also
- Media handling guide - Upload and download media
- Upload API - Upload media files
- Download API - Download media files