createFileMessageByURL
Feature Introduction
Description
When you need to store resources yourself, you can upload the file via the API, obtain the download address, and then send the file message to the other party.
Note
The message created through this API must be sent using the sendMessageNotOss method.
- 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 | Mandatory | 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 | Mandatory | 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 | Mandatory | 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.createFileMessage({
filePath: string;
fileName: string;
uuid: string;
sourceUrl: string;
fileSize: number;
fileType?: string;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
filePath | string | Yes | File path, use an empty string if needed |
fileName | string | Yes | File name |
uuid | string | Yes | Unique file ID |
sourceUrl | string | Yes | Image download URL. After uploading the file yourself and getting the remote URL, you need to send via sendMessageNotOss |
fileSize | number | Yes | File size |
fileType | string | Yes | File type, typically the file extension |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<MessageItem>> | Successful callback |
Promise.catch() | Promise<WsResponse> | Failed 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 { OpenIMSDK } from 'open-im-sdk';
// const IMSDK = new OpenIMSDK();
IMSDK.createFileMessage({
filePath: '',
fileName: 'fileName.mp4',
uuid: 'uuid',
sourceUrl: '',
fileSize: 1024,
fileType: 'mp4',
})
.then(({ data }) => {
// Successful invocation
})
.catch(({ errCode, errMsg }) => {
// Invocation 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 | Mandatory | Description |
---|---|---|---|
operationID | string | Yes | Operation ID, for problem localization, must be unique. It's recommended to use the current time and a random number. |
filePath | string | Yes | File path, just pass an empty string. |
fileName | string | Yes | File name. |
uuid | string | Yes | Unique file ID. |
sourceUrl | string | Yes | Image download link. After uploading the file and getting the remote URL, you need to send it via sendMessageNotOss. |
fileSize | string | Yes | File size. |
fileType | string | Yes | File type, usually the extension. |
Return Results
Using the
openim-uniapp-polyfill
package makes the function Promise-based. When invoking, you need to usethen
andcatch
to handle successful and failed callbacks.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<MessageItem> | Successful callback |
Promise.catch() | Promise<CatchResponse> | Failed callback |
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) => {
// Successful invocation
})
.catch(({ errCode, errMsg }) => {
// Invocation failed
});
Function Prototype
OpenIMSDKRN.createFileMessageByURL( {
filePath: string,
fileName: string,
uuid: string,
sourceUrl: string,
fileSize: number,
fileType: string,
}, operationID: string): Promise<MessageItem>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
filePath | string | Yes | File path, just pass an empty string. |
fileName | string | Yes | File name |
uuid | string | Yes | File unique ID |
sourceUrl | string | Yes | Image download link. After uploading the file and getting the remote URL, you need to send it via sendMessageNotOss. |
fileSize | string | Yes | File size |
fileType | string | Yes | File type, usually the extension |
operationID | string | Yes | Operation ID, used for problem location, keep unique, suggest using current time and random number |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<MessageItem> | Callback on successful call |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.createFileMessageByURL({
filePath: '',
fileName: 'fileName.mp4',
uuid: 'uuid',
sourceUrl: 'https://sourceUrl.mp4',
fileSize: 1024,
fileType: 'mp4',
}, 'operationID')
.then((data) => {
// Successful invocation
})
.catch(({ errCode, errMsg }) => {
// Invocation failed
});
Function Prototype
public static Message CreateFileMessageByURL(FileElem fileElem)
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
fileElem | FileElem | Yes | File Element |
Return Result
Parameter Name | Type | Description |
---|---|---|
~ | Message | Message Struct |
Code Example
var msg = IMSDK.CreateFileMessageByURL(new FileElem(){
});