Browse SDKs · uni-app / uni-app x
Platform
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.

Copy

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

ParameterTypeRequiredDescription
filePathstringNoOriginal local file path; pass an empty string "" when using remote assets.
uuidstringNoUnique asset identifier returned by the upload service.
sourceUrlstringRecommendedRemote download URL of the file.
fileNamestringRecommendedFile name and extension presented to recipients.
fileSizenumberRecommendedFile 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) return

While 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.