Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create file message from URL

Create a file message from pre-uploaded remote file metadata.

Copy

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

ParameterTypeRequiredDescription
filePathstringYesLocal file path if available, or an empty string "" for pure remote resources.
uuidstringYesUnique identifier for the uploaded file asset.
sourceURLstringYesRemote download URL of the file.
fileNamestringYesOriginal file name including extension.
fileSizenumberYesFile size in bytes.
fileTypestringYesMIME type of the file.

Return value

Returns a Promise resolving to CreateFileMessageResp:

PropertyTypeDescription
messageIMMessageLocally 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.