upload method
Future<void>
upload({
- required String containerId,
- required String filePath,
- required String destinationRelativePath,
- StreamHandler<
double> ? onProgress,
override
Upload a local file to iCloud.
containerId
is the iCloud Container Id.
filePath
is the full path of the local file.
destinationRelativePath
is the relative path of the file to be stored in
iCloud.
onProgress
is an optional callback to track the progress of the
upload. It takes a Stream
The returned future completes without waiting for the file to be uploaded to iCloud.
Implementation
@override
Future<void> upload({
required String containerId,
required String filePath,
required String destinationRelativePath,
StreamHandler<double>? onProgress,
}) async {
var eventChannelName = '';
if (onProgress != null) {
eventChannelName = _generateEventChannelName('upload', containerId);
await methodChannel.invokeMethod(
'createEventChannel', {'eventChannelName': eventChannelName});
final uploadEventChannel = EventChannel(eventChannelName);
final stream = uploadEventChannel
.receiveBroadcastStream()
.where((event) => event is double)
.map((event) => event as double);
onProgress(stream);
}
await methodChannel.invokeMethod('upload', {
'containerId': containerId,
'localFilePath': filePath,
'cloudFileName': destinationRelativePath,
'eventChannelName': eventChannelName
});
}