SDKsiOS
Upload a file
Upload a standalone file with the OpenIM iOS SDK.
Use standalone file uploads for user avatars, group avatars, profile attachments, or custom business files that do not directly belong to a message.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
fullPath | NSString * | Yes | Absolute filesystem path readable by the iOS application sandbox. |
name | NSString * | No | Target filename on the remote store. Pass nil to use the last path component of fullPath. |
cause | NSString * | Yes | Business upload category or tag agreed upon with the backend. |
onProgress | OIMUploadProgressCallback | No | Closure receiving saved bytes, currently uploaded bytes, and total file bytes. |
onCompletion | OIMUploadCompletionCallback | No | Closure 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.
Was this page helpful?