uploadFile method
Future<void>
uploadFile({
- required String containerId,
- required String localPath,
- required String cloudRelativePath,
- StreamHandler<
ICloudTransferProgress> ? onProgress,
override
Copy a local file into the iCloud container (copy-in).
containerId is the iCloud Container Id.
localPath is the full path of the local file to copy.
cloudRelativePath is the relative path inside the iCloud container.
Trailing slashes are rejected here because transfers are file-centric and coordinated through UIDocument/NSDocument (directories are not supported).
onProgress is an optional callback to track the progress of the upload.
It receives a Stream<ICloudTransferProgress> that emits:
- progress events with ICloudTransferProgress.percent
- terminal
doneevents - terminal
errorevents (data events, not streamonError)
The returned future completes once the copy finishes; iCloud uploads the file automatically in the background. The local file is not kept in sync.
Implementation
@override
Future<void> uploadFile({
required String containerId,
required String localPath,
required String cloudRelativePath,
StreamHandler<ICloudTransferProgress>? onProgress,
}) async {
var eventChannelName = '';
if (onProgress != null) {
eventChannelName = _generateEventChannelName('uploadFile', containerId);
await methodChannel.invokeMethod(
'createEventChannel',
{'eventChannelName': eventChannelName},
);
final uploadEventChannel = EventChannel(eventChannelName);
final stream = _receiveTransferProgressStream(uploadEventChannel);
onProgress(stream);
}
await methodChannel.invokeMethod('uploadFile', {
'containerId': containerId,
'localFilePath': localPath,
'cloudRelativePath': cloudRelativePath,
'eventChannelName': eventChannelName,
});
}