This package provides an XMTP content type to support sending file attachments that are stored off-network. Use it to enable your app to send and receive message attachments.
Attachments are files. More specifically, attachments are objects that have:
filenameMost files have names, at least the most common file types.mimeTypeWhat kind of file is it? You can often assume this from the file extension, but it's nice to have a specific field for it. Here's a list of common mime types.dataWhat is this file's data? Most files have data. If the file doesn't have data, then it's probably not the most interesting thing to send.
Because XMTP messages can only be up to 1MB in size, we need to store the attachment somewhere other than the XMTP network. In other words, we need to store it in a remote location.
End-to-end encryption must apply not only to XMTP messages, but to message attachments as well. For this reason, we need to encrypt the attachment before we store it.
# npm
npm i @xmtp/content-type-remote-attachment
# yarn
yarn add @xmtp/content-type-remote-attachment
# pnpm
pnpm i @xmtp/content-type-remote-attachmentRun yarn dev to build the content type and watch for changes, which will trigger a rebuild.
For more information on contributing to this repository, see our contributing guidelines.
Error:
content digest does not match
A digest is a cryptographic fingerprint (hash) of the attachment.
The "content digest error" occurs when the hash of the downloaded content doesn't match the expected hash reported in the message. The most common cause is uploading an unencrypted file to remote storage while including the digest of the encrypted version in your RemoteAttachment message. In this case, the digest of the unencrypted file won't match the digest of the encrypted file.
unable to fetch remote attachment
The RemoteAttachmentCodec.load function downloads an attachment from a remote location. In decentralized environments, content may not be immediately available, causing fetches to fail if you attempt to download before the file has fully distributed. Implementing a retry mechanism can help handle these cases.