createImageMessageByURL
Feature Introduction
Description
When you need to store resources yourself, you can upload images through the API, obtain a download address, and then create an image message to send to the recipient.
Note
The message 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 device. If not available, pass an empty string. |
sourcePicture | PictureInfo | Yes | Information related to the original image |
bigPicture | PictureInfo | Yes | Information related to the large image |
snapshotPicture | PictureInfo | Yes | Information related to the thumbnail image |
Return Result
Name | Type | Description |
---|---|---|
~ | Message | Successful 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 device. If not available, pass an empty string. |
source | OIMPictureInfo | Yes | Information related to the original image |
big | OIMPictureInfo | Yes | Information related to the large image |
snapshot | OIMPictureInfo | Yes | Information related to the thumbnail image |
Return Result
Name | Type | Description |
---|---|---|
message | OIMMessageInfo | Successful 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 | Information related to the original image |
bigPicture | PictureInfo | Yes | Information related to the large image |
snapshotPicture | PictureInfo | Yes | Information related to the thumbnail image |
Return Result
Name | Type | Description |
---|---|---|
~ | Message | Successful 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 | Information about the original image |
bigPicture | PicBaseInfo | Yes | Information about the large image |
snapshotPicture | PicBaseInfo | Yes | Information about the thumbnail image |
sourcePath | string | Yes | Absolute path of the image on the device, if none, pass an empty string |
Return Results
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<MessageItem>> | Successful callback |
Promise.catch() | Promise<WsResponse> | Failure callback |
Code Sample
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();
const picBaseInfo = {
uuid: "uuid",
type: "png",
size: 1024,
width: 1024,
height: 1024,
url: "http://xxx.com/xxx.png", // If sending through sendMessageByBuffer, fill in an empty string
}
IMSDK.createImageMessage({
sourcePicture: picBaseInfo;
bigPicture: picBaseInfo;
snapshotPicture: picBaseInfo;
sourcePath: string;
})
.then(({ data }) => {
// Successful call
})
.catch(({ errCode, errMsg }) => {
// Failed call
});
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 for problem tracking, ensure uniqueness, recommend using current time and random number |
sourcePicture | PicBaseInfo | Yes | Information about the original image |
bigPicture | PicBaseInfo | Yes | Information about the large image |
snapshotPicture | PicBaseInfo | Yes | Information about the thumbnail image |
sourcePath | string | Yes | Absolute path of the image on the device, if none, pass an empty string |
Return Results
The function is made Promise-type via the
openim-uniapp-polyfill
package. When calling, usethen
andcatch
to determine and handle successful and failed callbacks.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<MessageItem> | Successful callback |
Promise.catch() | Promise<CatchResponse> | Failure callback |
Code Sample
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) => {
// Successful call
})
.catch(({ errCode, errMsg }) => {
// Failed call
});
Function Prototype
OpenIMSDKRN.createImageMessageByURL({
sourcePicture: PicBaseInfo,
bigPicture: PicBaseInfo,
snapshotPicture: PicBaseInfo,
}, operationID: string): Promise<MessageItem>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
sourcePicture | PicBaseInfo | Yes | Information about the original image |
bigPicture | PicBaseInfo | Yes | Information about the large image |
snapshotPicture | PicBaseInfo | Yes | Information about the thumbnail image |
sourcePath | string | Yes | Absolute path of the image on the device, if none, pass an empty string |
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";
const picBaseInfo = {
uuid: 'uuid',
type: 'png',
size: 1024,
width: 1024,
height: 1024,
url: 'http://xxx.com/xxx.png',
};
OpenIMSDKRN.createImageMessageByURL({
sourcePicture: picBaseInfo,
bigPicture: picBaseInfo,
snapshotPicture: picBaseInfo,
sourcePath: ""
}, 'operationID')
.then((data) => {
// Successful call
})
.catch(({ errCode, errMsg }) => {
// Failed call
});
Function Prototype
public static Message CreateImageMessageByURL(string sourcePath, PictureBaseInfo sourcePicture, PictureBaseInfo bigPicture, PictureBaseInfo snapshotPicture)
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
sourcePath | string | Yes | Absolute path of the image on the device, if none, pass an empty string |
sourcePicture | PictureInfo | Yes | Information about the original image |
bigPicture | PictureInfo | Yes | Information about the large image |
snapshotPicture | PictureInfo | Yes | Information about the thumbnail image |
Return Result
Parameter Name | Type | Description |
---|---|---|
~ | Message | Message Struct |
Code Example
var msg = IMSDK.CreateImageMessageByURL(sourcePath,sourcePicture, bigPicture, snapshotPicture);