SDKsHarmonyOSEnterprise
Create file message from URL
Create a file message from pre-uploaded remote file metadata.
Creates a file message using remote resource metadata when the file has already been uploaded by application servers or cloud storage.
Code example
import sdk, { CreateFileMessageByURLReq, CreateFileMessageResp } from '@openimsdk/imsdk';
const request: CreateFileMessageByURLReq = {
filePath: '',
uuid: uploaded.uuid,
sourceURL: uploaded.url,
fileName: 'ProjectPlan.pdf',
fileSize: uploaded.size,
fileType: 'application/pdf',
};
const response: CreateFileMessageResp = await sdk.createFileMessageByURL(request);
const message = response.message;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Local file path if available, or an empty string "" for pure remote resources. |
uuid | string | Yes | Unique identifier for the uploaded file asset. |
sourceURL | string | Yes | Remote download URL of the file. |
fileName | string | Yes | Original file name including extension. |
fileSize | number | Yes | File size in bytes. |
fileType | string | Yes | MIME type of the file. |
Return value
Returns a Promise resolving to CreateFileMessageResp:
| Property | Type | Description |
|---|---|---|
message | IMMessage | Locally instantiated file message object. |
State changes after the call
All fields are required; pass an empty string "" for filePath when referencing remote assets only. Receiving clients must still validate download endpoints, MIME types, and file sizes without blindly trusting extensions. This operation creates the message object locally; call Send message to transmit it.
Was this page helpful?