Browse SDKs · uni-app / uni-app x
SDKsuni-app

Create a file message from a URL

OpenIM uni-app / uni-app x SDK guide for Create a file message from a URL.

Copy

Use createFileMessageByURL() with metadata from a file that is already uploaded.

Parameters

ParameterTypeDescription
filePathstring or nullLocal name or business path; use an empty string when only a remote resource exists.
fileNamestring or nullDisplay filename.
uuidstring or nullUnique resource identifier.
sourceUrlstring or nullAccessible URL of the uploaded file.
fileSizenumber or nullFile size in bytes.
import { createFileMessageByURL } from '@/uni_modules/unix-openim-sdk'

const message = await createFileMessageByURL({
  filePath: '',
  fileName: 'report.pdf',
  uuid: createBusinessUUID(),
  sourceUrl: uploaded.url,
  fileSize: uploaded.size,
})

Use real upload-result URL, name, UUID, and size values. The URL must be accessible to recipients without exposing private storage credentials. OpenIMFileElem does not contain the Wasm fileType field.

The Promise creates OpenIMMessageItem | null. Because the resource is already uploaded, send it with sendMessageNotOss().