createImageMessageByURL
Description
info
When you need to store resources yourself, upload the image via API and obtain the download URL, then create an image 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> createImageMessageByURL({
required String sourcePath,
required PictureInfo sourcePicture,
required PictureInfo bigPicture,
required PictureInfo snapshotPicture,
String? operationID,
})
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| sourcePath | String | Yes | Absolute path of the image on the local machine; if none, empty string is fine |
| sourcePicture | PictureInfo | Yes | Original image information |
| bigPicture | PictureInfo | Yes | Large image information |
| snapshotPicture | PictureInfo | Yes | Thumbnail information |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
Message msg = await OpenIM.iMManager.messageManager.createImageMessageByURL(sourcePath: '', sourcePicture: sourcePicture, bigPicture: bigPicture, snapshotPicture: snapshotPicture);
//todo
Function Prototype
+ (OIMMessageInfo *)createImageMessageByURL:(NSString *)sourcePath
sourcePicture:(OIMPictureInfo *)source
bigPicture:(OIMPictureInfo *)big
snapshotPicture:(OIMPictureInfo *)snapshot;
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| sourcePath | String | Yes | Absolute path of the image on the local machine; if none, empty string is fine |
| source | OIMPictureInfo | Yes | Original image information |
| big | OIMPictureInfo | Yes | Large image information |
| snapshot | OIMPictureInfo | Yes | Thumbnail information |
Return Result
| Name | Type | Description |
|---|---|---|
| message | OIMMessageInfo | Success return |
Code Example
OIMPictureInfo *source = [OIMPictureInfo new];
source.url = @"";
OIMPictureInfo *big = [OIMPictureInfo new];
big.url = @"";
OIMPictureInfo *snapshot = [OIMPictureInfo new];
snapshot.url = @"";
OIMMessageInfo *message = [OIMMessageInfo createImageMessageByURL:sourcePath sourcePicture:source bigPicture:big snapshotPicture:snapshot];
Function Prototype
public Message createImageMessageByURL(PictureInfo sourcePicture, PictureInfo bigPicture, PictureInfo snapshotPicture)
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| sourcePicture | PictureInfo | Yes | Original image information |
| bigPicture | PictureInfo | Yes | Large image information |
| snapshotPicture | PictureInfo | Yes | Thumbnail information |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
Message Message= OpenIMClient.getInstance().messageManager. createImageMessageByURL( sourcePicture, bigPicture, snapshotPicture)
Function Prototype
IMSDK.createImageMessageByURL({
sourcePicture: PicBaseInfo;
bigPicture: PicBaseInfo;
snapshotPicture: PicBaseInfo;
sourcePath: string;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| sourcePicture | PicBaseInfo | Yes | Original image information |
| bigPicture | PicBaseInfo | Yes | Large image information |
| snapshotPicture | PicBaseInfo | Yes | Thumbnail information |
| sourcePath | string | Yes | Absolute path of the image on the local machine; if none, empty string is fine |
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();
const picBaseInfo = {
uuid: "uuid",
type: "png",
size: 1024,
width: 1024,
height: 1024,
url: "http://xxx.com/xxx.png", // Fill with an empty string when sending via sendMessageByBuffer
}
IMSDK.createImageMessage({
sourcePicture: picBaseInfo;
bigPicture: picBaseInfo;
snapshotPicture: picBaseInfo;
sourcePath: string;
})
.then(({ data }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
IMSDK.asyncApi('createImageMessageByURL', operationID: string, {
sourcePicture: PicBaseInfo;
bigPicture: PicBaseInfo;
snapshotPicture: PicBaseInfo;
sourcePath: 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 |
| sourcePicture | PicBaseInfo | Yes | Original image information |
| bigPicture | PicBaseInfo | Yes | Large image information |
| snapshotPicture | PicBaseInfo | Yes | Thumbnail information |
| sourcePath | string | Yes | Absolute path of the image on the local machine; if none, empty string is fine |
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.
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<MessageItem> | Success callback |
| Promise.catch() | Promise<CatchResponse> | Failure callback |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
const picBaseInfo = {
uuid: 'uuid',
type: 'png',
size: 1024,
width: 1024,
height: 1024,
url: 'http://xxx.com/xxx.png',
};
IMSDK.asyncApi(
'createImageMessageByURL',
IMSDK.uuid(),
{
sourcePicture: picBaseInfo;
bigPicture: picBaseInfo;
snapshotPicture: picBaseInfo;
sourcePath: ""
}
)
.then((data) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDK.createImageMessageByURL({
sourcePicture: PicBaseInfo,
bigPicture: PicBaseInfo,
snapshotPicture: PicBaseInfo,
}, operationID?: string): Promise<MessageItem>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| sourcePicture | PicBaseInfo | Yes | Original image information |
| bigPicture | PicBaseInfo | Yes | Large image information |
| snapshotPicture | PicBaseInfo | Yes | Thumbnail information |
| sourcePath | string | Yes | Absolute path of the image on the local machine; if none, empty string is fine |
| 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";
const picBaseInfo = {
uuid: 'uuid',
type: 'png',
size: 1024,
width: 1024,
height: 1024,
url: 'http://xxx.com/xxx.png',
};
OpenIMSDK.createImageMessageByURL({
sourcePicture: picBaseInfo,
bigPicture: picBaseInfo,
snapshotPicture: picBaseInfo,
sourcePath: ""
})
.then((data) => {
// Call successful
})
.catch((error) => {
// Call failed
});
Function Prototype
public static Message CreateImageMessageByURL(string sourcePath, PictureBaseInfo sourcePicture, PictureBaseInfo bigPicture, PictureBaseInfo snapshotPicture)
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| sourcePath | string | Yes | Absolute path of the image on the local machine; if none, empty string is fine |
| sourcePicture | PictureInfo | Yes | Original image information |
| bigPicture | PictureInfo | Yes | Large image information |
| snapshotPicture | PictureInfo | Yes | Thumbnail information |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
var msg = IMSDK.CreateImageMessageByURL(sourcePath,sourcePicture, bigPicture, snapshotPicture);