createDirectory method

  1. @override
Future<void> createDirectory(
  1. String path
)
override

Creates a new directory at the specified path.

Implementation

@override
Future<void> createDirectory(String path) {
  return _executeRequest(() async {
    final normalizedPath = _normalizePath(path);
    debugPrint('Creating Dropbox directory: $normalizedPath');
    try {
      await _dio.post(
        'https://api.dropboxapi.com/2/files/create_folder_v2',
        data: jsonEncode({'path': normalizedPath, 'autorename': false}),
        options: Options(contentType: 'application/json'),
      );
      debugPrint('Successfully created directory: $normalizedPath');
    } on DioException catch (e) {
      // If the directory already exists, treat it as a success.
      if (e.response?.data?['error_summary']
              ?.contains('path/conflict/folder') ==
          true) {
        debugPrint(
            'Directory already exists, ignoring creation: $normalizedPath');
      } else {
        rethrow;
      }
    }
  });
}