Browse SDKs · Android
Platform
SDKsAndroid

Create an image message from URLs

Use createImageMessageByURL to create an image message for an uploaded resource.

Copy

Construct an image message object using remote image URLs hosted on external cloud storage or a CDN. The SDK does not re-upload the image, making this suitable for applications managing their own file storage pipelines.

Code example

String sourceURL = "https://example.com/images/origin.jpg";

PictureInfo sourcePicture = new PictureInfo();
sourcePicture.setUrl(sourceURL);
sourcePicture.setWidth(1080);
sourcePicture.setHeight(1920);

PictureInfo bigPicture = sourcePicture;

PictureInfo snapshotPicture = new PictureInfo();
snapshotPicture.setUrl("https://example.com/images/thumb.jpg");
snapshotPicture.setWidth(200);
snapshotPicture.setHeight(355);

Message message = OpenIMClient.getInstance().messageManager.createImageMessageByURL(
    sourceURL,
    sourcePicture,
    bigPicture,
    snapshotPicture
);

Parameters

ParameterTypeRequiredDescription
sourceURLStringYesAccessible remote URL of the original image.
sourcePicturePictureInfoYesOriginal image metadata object containing URL, width, height, and size.
bigPicturePictureInfoYesHigh-resolution image metadata object. Pass the original picture metadata if a separate high-res variant is not generated.
snapshotPicturePictureInfoYesThumbnail image metadata object used for fast preview in the message list.

Return value

Returns the created Message object ready for transmission, with contentType set to MessageType.PICTURE.

State changes after the call

  1. Local initialization: Initializes the local Message structure without issuing network requests.
  2. Transmission: Because the media asset is pre-hosted, call Send a message without OSS upload to deliver the message without redundant uploads.