Browse SDKs · iOS
Platform
SDKsiOS

Upload a file

Upload a standalone file with the OpenIM iOS SDK.

Copy

Use standalone file uploads for user avatars, group avatars, profile attachments, or custom business files that do not directly belong to a message.

Parameters

ParameterTypeRequiredDescription
fullPathNSString *YesAbsolute filesystem path readable by the iOS application sandbox.
nameNSString *NoTarget filename on the remote store. Pass nil to use the last path component of fullPath.
causeNSString *YesBusiness upload category or tag agreed upon with the backend.
onProgressOIMUploadProgressCallbackNoClosure receiving saved bytes, currently uploaded bytes, and total file bytes.
onCompletionOIMUploadCompletionCallbackNoClosure receiving total bytes, the remote URL, and storage type (putType).

Code example

[[OIMManager manager] uploadFile:fileURL.path
                            name:fileURL.lastPathComponent
                           cause:@"user-avatar"
                      onProgress:^(NSInteger saved, NSInteger current, NSInteger total) {
    [uploadStore updateCurrentBytes:current totalBytes:total];
}
                    onCompletion:^(NSInteger total, NSString *url, NSInteger putType) {
    [profileService saveAvatarURL:url];
}
                       onSuccess:nil
                       onFailure:^(NSInteger code, NSString *message) {
    NSLog(@"uploadFile failed: %ld %@", (long)code, message);
}];

Return value

The onCompletion callback provides the remote resource URL, total size in bytes, and storage engine type (putType). The overall operational status resolves through onSuccess or onFailure.

Uploading a file does not alter user profiles or automatically construct messages. To share the uploaded file in a chat session, supply the returned URL to the corresponding URL-based message creation method and send it explicitly.