createFileMessageByURL
Description
info
When you need to store resources yourself, upload the file via API and obtain the download URL, then call this API to create a file message.
Note
Messages created through this API must be sent via sendMessageNotOss.
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<Message> createFileMessageByURL({
required FileElem fileElem,
String? operationID,
})
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| fileElem | FileElem | Yes | Absolute path |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
Message msg = await OpenIM.iMManager.messageManager.createFileMessageByURL(fileElem: FileElem());
//todo
Function Prototype
+ (OIMMessageInfo *)createFileMessageByURL:(NSString *)fileURL
fileName:(NSString * _Nullable)fileName
size:(NSInteger)size;
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| fileURL | NSString | Yes | Absolute path |
| fileName | NSString | No | File name |
| size | NSInteger | Yes | File size |
Return Result
| Name | Type | Description |
|---|---|---|
| message | OIMMessageInfo | Success return |
Code Example
OIMMessageInfo *message = [OIMMessageInfo createFileMessageByURL:@"" fileName:nil, size:1];
Function Prototype
public Message createFileMessageByURL(FileElem fileElem)
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| fileElem | FileElem | Yes | Absolute path |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
Message Message= OpenIMClient.getInstance().messageManager.createFileMessageByURL( fileElem)
Function Prototype
IMSDK.createFileMessageByURL({
filePath: string;
fileName: string;
uuid: string;
sourceUrl: string;
fileSize: number;
fileType?: string;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| filePath | string | Yes | File path, empty string is fine |
| fileName | string | Yes | File name |
| uuid | string | Yes | Unique file ID |
| sourceUrl | string | Yes | Download address. When uploading the file yourself and sending via sendMessageNotOss, this needs to be the remote URL; otherwise, it should be an empty string |
| fileSize | string | Yes | File size |
| fileType | string | Yes | File type, usually the extension |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<WsResponse<MessageItem>> | Success callback |
| Promise.catch() | Promise<WsResponse> | Failure callback |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();
IMSDK.createFileMessageByURL({
filePath: '',
fileName: 'fileName.mp4',
uuid: 'uuid',
sourceUrl: '',
fileSize: 1024,
fileType: 'mp4',
})
.then(({ data }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
IMSDK.asyncApi('createFileMessageByURL', operationID: string, {
filePath: string;
fileName: string;
uuid: string;
sourceUrl: string;
fileSize: number;
fileType: string;
}): Promise<MessageItem>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| operationID | string | Yes | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
| filePath | string | Yes | File path, empty string is fine |
| fileName | string | Yes | File name |
| uuid | string | Yes | Unique file ID |
| sourceUrl | string | Yes | Remote URL address obtained after uploading the file yourself. Needs to be sent via sendMessageNotOss |
| fileSize | string | Yes | File size |
| fileType | string | Yes | File type, usually the extension |
Return Result
Use the
openim-uniapp-polyfillpackage to make the function Promise. When calling, you need to usethenandcatchto determine and handle success and failure callbacks.
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('createFileMessageByURL', IMSDK.uuid(), {
filePath: '',
fileName: 'fileName.mp4',
uuid: 'uuid',
sourceUrl: 'https://sourceUrl.mp4',
fileSize: 1024,
fileType: 'mp4',
})
.then((data) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDK.createFileMessageByURL( {
filePath: string,
fileName: string,
uuid: string,
sourceUrl: string,
fileSize: number,
fileType: string,
}, operationID?: string): Promise<MessageItem>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| filePath | string | Yes | File path, empty string is fine |
| fileName | string | Yes | File name |
| uuid | string | Yes | Unique file ID |
| sourceUrl | string | Yes | Remote URL address obtained after uploading the file yourself. Needs to be sent via sendMessageNotOss |
| fileSize | string | Yes | File size |
| fileType | string | Yes | File type, usually the extension |
| operationID | string | No | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<MessageItem> | Success callback |
| Promise.catch() | Promise<OpenIMApiError> | Failure callback |
Code Example
import OpenIMSDK from "@openim/rn-client-sdk";
OpenIMSDK.createFileMessageByURL({
filePath: '',
fileName: 'fileName.mp4',
uuid: 'uuid',
sourceUrl: 'https://sourceUrl.mp4',
fileSize: 1024,
fileType: 'mp4',
})
.then((data) => {
// Call successful
})
.catch((error) => {
// Call failed
});
Function Prototype
public static Message CreateFileMessageByURL(FileElem fileElem)
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| fileElem | FileElem | Yes | Absolute path |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
var msg = IMSDK.CreateFileMessageByURL(new FileElem(){
});