SDKsuni-app / uni-app x
Create a file message from a URL
Construct a pending file attachment message from an uploaded file URL and metadata.
Invoke createFileMessageByURL() when a file attachment has already been uploaded to your application server or cloud storage provider and has a publicly accessible remote URL.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | No | Original local file path; pass an empty string "" when using remote assets. |
uuid | string | No | Unique asset identifier returned by the upload service. |
sourceUrl | string | Recommended | Remote download URL of the file. |
fileName | string | Recommended | File name and extension presented to recipients. |
fileSize | number | Recommended | File size in bytes. |
Code example
import { createFileMessageByURL } from '@/uni_modules/unix-openim-sdk'
const message = await createFileMessageByURL({
filePath: '',
uuid: uploaded.uuid,
sourceUrl: uploaded.url,
fileName: 'project-plan.pdf',
fileSize: uploaded.size,
})
if (message == null) returnWhile individual properties are typed as optional, constructing a usable file message requires a valid sourceUrl, accurate fileName, and correct fileSize.
Return value
The Promise resolves with an OpenIMMessageItem | null object.
State changes after the call
Pass the constructed message item to Send a non-OSS message to deliver the payload without re-uploading the file. Track message state using clientMsgID.
Was this page helpful?