Browse SDKs · Android
Platform
SDKsAndroid

Create a file message from a URL

Use FileElem to create a file message for an uploaded resource.

Copy

Construct a file message object using a pre-uploaded remote URL hosted on your own cloud storage or enterprise file management system. The SDK does not re-upload the file, making this suitable for integrations with existing document storage repositories.

Code example

FileElem fileElem = new FileElem();
fileElem.setSourceUrl("https://example.com/files/report.pdf");
fileElem.setFileName("Project_Report.pdf");
fileElem.setFileSize(2048000L);

Message message = OpenIMClient.getInstance().messageManager.createFileMessageByURL(fileElem);

Parameters

ParameterTypeRequiredDescription
fileElemFileElemYesFile model object. Must specify the remote download URL sourceUrl, file name fileName, and file size fileSize.

Return value

Returns the created Message object ready for transmission, with contentType set to MessageType.FILE.

State changes after the call

  1. Local initialization: Initializes the local Message structure without starting network uploads.
  2. Transmission: Because the file asset is pre-hosted, call Send a message without OSS upload to deliver the message without redundant uploads.