Browse SDKs · React Native
Platform
SDKsReact Native

Create file message from URL

Construct a file message using pre-uploaded remote file metadata and URL using the OpenIM React Native SDK.

Copy

Construct a file message using remote resource metadata from a pre-uploaded file:

const message = await OpenIMSDK.createFileMessageByURL({
  filePath: '',
  fileName: 'product-specification.pdf',
  uuid: 'file-001',
  sourceUrl: 'https://www.example.com/product-specification.pdf',
  fileSize: 256000,
  fileType: 'application/pdf',
});

Parameters

ParameterTypeRequiredDescription
filePathstringYesLocal filesystem path; pass empty string "" when using remote-only assets.
fileNamestringYesDisplay filename presented in the message view.
uuidstringYesUnique resource identifier for the file.
sourceUrlstringYesAccessible remote URL where the file is hosted.
fileSizenumberYesSize of the file in bytes.
fileTypestringNoFile MIME type (e.g. 'application/pdf').

Return value

A resolved Promise returns the initialized MessageItem object with remote file properties stored in fileElem.

This method builds the message structure strictly in client memory; it does not dispatch messages to the server or trigger lifecycle events. After initialization, invoke Send uploaded media message to deliver it to a conversation without repeating file uploads.