Skip to main content

File Message

Users can send file messages through the built-in file plugin in IMKit. The messages will appear in the message list component of the chat UI. By default, the file plugin sends messages containing the file message content object FileMessage (type identifier: RC:FileMsg).

message-file-unread(width=250) (width=250)

Limitations

  • Only supports sending local files.
  • Files in file messages are uploaded to RC servers by default. To upload to your own server, you need to intercept the message and handle the upload manually. See Message Interception.
  • File preview isn't supported in IMKit. Use other apps to open files from the UI.

Usage

The built-in FilePlugin in IMKit implements the file message feature in the extension panel. You can also refer to the FilePlugin.java in IMKit's source code.

Sending File Messages

The extension panel includes a file message entry by default. Users can tap the + button on the right side of the input bar to expand the extension panel, then tap the file icon to send a file message.

extension(width=250)

Customization

Modify Default File Save Location

When saving received file messages by long-pressing in the chat UI, the SDK saves them to /RongCloud/File/ by default. To change this globally, create an rc_config file in your app's res/values/ directory:

<string name="rc_file_default_saved_path">/RongCloud/File/</string>

Replace Default File Icons for File Messages

When displaying FileMessage in the chat UI, matched icons are shown based on the file type. The SDK provides default icons for the following file categories. Other file types display a unified default icon.

  • Images: bmp, cod, gif, ief, jpe, jpeg, jpg, jfif, svg, tif, tiff, ras, ico, pbm, pgm, png, pnm, ppm, xbm, xpm, xwd, rgb
  • Text: txt, log, html, stm, uls, bas, c, h, rtx, sct, tsv, htt, htc, etx, vcf
  • Video: rmvb, avi, mp4, mp2, mpa, mpe, mpeg, mpg, mpv2, mov, qt, lsf, lsx, asf, asr, asx, avi, movie, wmv
  • Audio: mp3, au, snd, mid, rmi, aif, aifc, aiff, m3u, ra, ram, wav, wma
  • Word: doc, dot, docx
  • Excel: xla, xlc, xlm, xls, xlt, xlw, xlsx

Starting from SDK v5.3.4, apps can modify icons for specific file extensions. You can update individual icons, replace all icons, or add new file extensions with corresponding icons.

We recommend calling this before initialization.

Interface

RongConfigCenter.conversationConfig().registerFileSuffixTypes(map);

Parameters

ParameterTypeDescription
mapHashMap<String, Integer>File message icon configuration. The key is a file extension without . (e.g., png, pdf). The value is an Android resource ID (add icons to the drawable directory). Use default as the key to replace the unified default file icon.

Customize File Message UI

File messages are displayed in the message list using the FileMessageItemProvider template. To modify the built-in message style, implement your own message template class and provide it to the SDK. All message templates inherit from BaseMessageItemProvider<CustomMessage>. For details, see Customize Message Display.

You can also directly replace style resources, string resources, or icon resources referenced in the file message display template. Refer to the resources used in FileMessageItemProvider.java in IMKit's source code.

Hide File Message Entry

IMKit enables the file message entry in the extension panel by default. To modify this dynamically, create a custom extension panel configuration class MyExtensionConfig that inherits from DefaultExtensionConfig and override the getPluginModules() method. See Input Area Extension Panel.