<divid="dev_page_content"><p>File references are strings of bytes, that can be encountered in the <code>file_reference</code> fields of <ahref="/constructor/document">document</a> and <ahref="/constructor/photo">photo</a> objects.</p>
<p>They must be cached by the client, along with the <strong>origin context</strong> where the document/photo object was found, in order to be refetched when the file reference expires.</p>
<p>Assume you receive a <ahref="/constructor/message">message</a> from your friend: that message contains a <ahref="/constructor/messageMediaPhoto">messageMediaPhoto</a> with a <ahref="/constructor/photo">photo</a>.</p>
<p>Your client has to cache not only the <code>file_reference</code> field of the photo, but also the context in which the file reference was seen (in this case, a message coming from a specific user).</p>
<p>The context info is in this case, <ahref="https://github.com/danog/MadelineProto/blob/v8/src/MTProtoTools/ReferenceDatabase.php#L74">an origin context of type message</a>, containing the message ID and the peer ID of the chat/channel/user where the message was seen.</p>
<p>The context info has to be associated with the file reference: when downloading a file using <ahref="/method/upload.getFile">upload.getFile</a> or resending it using <ahref="/method/messages.sendMedia">messages.sendMedia</a>, a <code>FILE_REFERENCE_EXPIRED</code> error may be returned.<br>
<ahref="/method/messages.sendMultiMedia">messages.sendMultiMedia</a> returns a variation of the same error, as a <code>FILE_REFERENCE_%d_EXPIRED</code> error (where <code>%d</code> is the index of the media with the expired file reference in the passed media array).<br>
If this happens, the context info must be used to refetch the object that contained the file reference: in this example, the peer info and the message ID have to be used with <ahref="/method/channels.getMessages">channels.getMessages</a> or <ahref="/method/messages.getMessages">messages.getMessages</a> to <ahref="https://github.com/danog/MadelineProto/blob/v8/src/MTProtoTools/ReferenceDatabase.php#L481">refetch the message</a>, recache the file reference and use it in a new file download request.</p>
<p>More than one origin context can be associated to one file reference, for greater resilience (in the case of a message that was deleted in one chat but was also forwarded in another chat, the file reference can be refetched from the second chat, instead).</p>
<p>Origin contexts for objects returned by method calls with certain parameters can be considered, too (for example, in the case of favorited sticker sets returned by <ahref="/method/messages.getFavedStickers">messages.getFavedStickers</a>).</p></div>
</div>
</div>
</div>
<divclass="footer_wrap">
<divclass="footer_columns_wrap footer_desktop">
<divclass="footer_column footer_column_telegram">
<h5>Telegram</h5>
<divclass="footer_telegram_description"></div>
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.