Browse SDKs · WASM
SDKsWASM

Create an audio message from a URL

Create an audio message from an uploaded resource URL with the WASM SDK.

Copy

createSoundMessageByURL() creates a message from information for an audio resource that has already been uploaded.

Parameters

ParameterTypeRequiredDescription
uuidstringYesUnique identifier for the audio resource.
soundPathstringYesLocal filename or application-defined path of the audio file. Pass an empty string when only a remote resource is available.
sourceUrlstringYesAccessible URL of the uploaded audio.
dataSizenumberYesAudio size in bytes.
durationnumberYesAudio duration.
soundTypestringNoAudio MIME type.
const { data: message } = await openimsdk.createSoundMessageByURL({
  uuid: crypto.randomUUID(),
  soundPath: '',
  sourceUrl: uploaded.url,
  dataSize: uploaded.size,
  duration,
  soundType: uploaded.contentType,
});

Use the byte count for dataSize and the duration value expected by the SDK for duration. The URL, type, and size must come from the actual upload result. When the Promise resolves, it has created only a pending message object; send it with sendMessageNotOss().