Skip to main content

Download Media Message Files

The SDK provides the functionality to download multimedia files.

Media Files in Media Messages

The content property of the RCMessage object may contain media message content, which includes the media file URL. Common media message contents are as follows:

When receiving such messages, you can use downloadMediaMessage to download the media files within them.

Download Media Files in Media Messages

tip

Starting from SDK version 5.6.6, the method to download media files by passing in RCMessage is provided, while the method to download media files by passing in the message ID is deprecated.

(SDK version ≧ 5.6.6) After downloading the media file locally, the localPath of the media file in the message content body RCMessageContent will be updated.

[[RCCoreClient sharedCoreClient] downloadMediaMessage:message
progressBlock:^(int progress) {
// Update UI with download progress
}
successBlock:^(NSString *mediaPath) {
// Handle successful download
}
errorBlock:^(RCErrorCode errorCode) {
// Handle download error
}
cancelBlock:^{
// Handle download cancellation
}];
ParameterTypeDescription
messageRCMessageThe message object.
progressBlockBlockCallback for the current download progress, returns an int type download progress, range [0, 100].
successBlockBlockCallback for successful download, returns a NSString type local path, and the localPath in the message content body will be updated to the returned mediaPath.
errorBlockBlockCallback for download failure, returns an error code RCErrorCode.
cancelBlockBlockCallback for download cancellation.

(SDK version < 5.6.6) After downloading the media file locally, the localPath of the media file in the message content body RCMessageContent will be updated.

[[RCCoreClient sharedCoreClient] downloadMediaMessage:messageId
progress:^(int progress) { }
success:^(NSString *mediaPath) { }
error:^(RCErrorCode errorCode) { }
cancel:^{ }];

Pause Downloading Media Files in Media Messages

tip

The pause download feature is only supported in version 5.6.6 and later.

You can pause the download during the process. To resume, call the download method again, which supports resuming from where it was paused.

[[RCCoreClient sharedCoreClient] pauseDownloadMediaMessage:message
successBlock:^{
// Handle pause success
}
errorBlock:^(RCErrorCode errorCode) {
// Handle pause error
}];

Cancel Downloading Media Files in Media Messages

tip

Starting from SDK version 5.6.6, an asynchronous method is provided, and the original synchronous method is deprecated.

(SDK version ≧ 5.6.6) Asynchronously cancel downloading media files in media messages. If RCErrorCode is -3/OPERATION_MEDIA_NOT_FOUND, it means the download task has ended or the message does not exist.

[[RCCoreClient sharedCoreClient] cancelDownloadMediaMessage:message
successBlock:^{
// Handle cancellation success
}
errorBlock:^(RCErrorCode errorCode) {
// Handle cancellation error
}];

(SDK version < 5.6.6) Cancel downloading media files in media messages. Returns YES if successful. Returns NO if failed, meaning the download has already completed or the message does not exist.

BOOL cancelResult = [[RCCoreClient sharedCoreClient] cancelDownloadMediaMessage:messageId];

Network Media Files

The SDK provides a media file downloader that can download files via a network URL without manipulating the message body.

Download Network Media Files via URL

Use this method to download files via URL, which does not manipulate the message body. The returned mediaPath will include the file name specified in the input parameters.

[[RCCoreClient sharedCoreClient] downloadMediaFile:@"filename.png"
mediaUrl:@"http://remote.url"
progress:^(int progress) { }
success:^(NSString *mediaPath) { }
error:^(RCErrorCode errorCode) { }
cancel:^{ } ];
ParameterTypeDescription
fileNamemediaUrlThe specified file name, must include the file extension, e.g., rongCloud.mov.
mediaUrlNSStringThe remote URL of the media file.
progressBlockBlockCallback for the current download progress, returns an int type download progress, range [0, 100].
successBlockBlockCallback for successful download, returns a NSString type local path.
errorBlockBlockCallback for download failure, returns an error code RCErrorCode.
cancelBlockBlockCallback for download cancellation.

Download images via the file's network URL. This method is merely a file downloader and does not manipulate the message body. The SDK will generate a file name by concatenating the input parameters of conversation type, conversation ID, and media type, and return it in mediaPath. This method only supports downloading images.

[[RCCoreClient sharedCoreClient] downloadMediaFile:ConversationType_GROUP
targetId:@"targetId"
mediaType:MediaType_IMAGE
mediaUrl:@"remoteurl"
progress:^(int progress) { }
success:^(NSString *mediaPath) { }
error:^(RCErrorCode errorCode) { }
cancel:^{ }];
ParameterTypeDescription
conversationTypeRCConversationTypeThe conversation type.
targetIdNSStringThe conversation ID.
mediaTypeRCMediaTypeThe media type, this method only supports downloading images (MediaType_IMAGE).
mediaUrlNSStringThe remote URL of the media file.
progressBlockBlockCallback for the current download progress, returns an int type download progress, range [0, 100].
successBlockBlockCallback for successful download, returns a NSString type local path.
errorBlockBlockCallback for download failure, returns an error code RCErrorCode.
cancelBlockBlockCallback for download cancellation.

Pause Downloading Network Media Files

tip

The pause download feature is only supported in version 5.6.6 and later.

You can pause the download during the process. To resume, call the download method again, which supports resuming from where it was paused.

[[RCCoreClient sharedCoreClient] pauseDownloadMediaUrl:mediaUrl
successBlock:^{
// Handle pause success
}
errorBlock:^(RCErrorCode errorCode) {
// Handle pause error
}];

Cancel Downloading Network Media Files

tip

Starting from SDK version 5.6.6, an asynchronous cancel download method is provided, and the original synchronous method is deprecated.

(SDK version ≧ 5.6.6) Asynchronously cancel downloading network media files. If RCErrorCode is -3/OPERATION_MEDIA_NOT_FOUND, it means the download task has ended.

[[RCCoreClient sharedCoreClient] cancelDownloadMediaUrl:mediaUrl
successBlock:^{
// Handle cancellation success
}
errorBlock:^(RCErrorCode errorCode) {
// Handle cancellation error
}];

(SDK version < 5.6.6) Cancel downloading network media files. Returns YES if successful. Returns NO if failed, meaning the download has already completed or the message does not exist.

BOOL cancelResult = [[RCCoreClient sharedCoreClient] cancelDownloadMediaUrl:@"remoteurl"];