uploadFile method

  1. @override
Future<String> uploadFile({
  1. required String localPath,
  2. required String remotePath,
  3. Map<String, dynamic>? metadata,
})
override

Uploads a file from a localPath to a remotePath in the cloud.

Implementation

@override
Future<String> uploadFile({
  required String localPath,
  required String remotePath,
  Map<String, dynamic>? metadata,
}) async {
  try {
    await _icloudSync.upload(
      containerId: _containerId,
      filePath: localPath,
      destinationRelativePath: _sanitizePath(remotePath),
    );
    return remotePath;
  } on PlatformException catch (e) {
    // ADD THIS CHECK: for "No Connection" (NSURLErrorDomain Code -1009)
    if (e.code == '-1009' ||
        e.toString().contains('NSURLErrorDomain Code=-1009')) {
      throw NoConnectionException(
          'Failed to upload to iCloud. Please check your internet connection.');
    }
    rethrow;
  }
}