deleteFile method

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

Deletes the file or directory at the specified path.

Implementation

@override
Future<void> deleteFile(String path) {
  return _executeRequest(() async {
    final normalizedPath = _normalizePath(path);
    debugPrint('Attempting to delete Dropbox path: $normalizedPath');
    try {
      await _dio.post(
        'https://api.dropboxapi.com/2/files/delete_v2',
        data: jsonEncode({'path': normalizedPath}),
        options: Options(contentType: 'application/json'),
      );
      debugPrint('Successfully deleted path: $normalizedPath');
    } on DioException catch (e) {
      // If the file doesn't exist, treat it as a successful deletion.
      if (e.response?.data?['error_summary']
              ?.contains('path_lookup/not_found') ==
          true) {
        debugPrint(
            'Path not found during deletion, considering it a success: $normalizedPath');
      } else {
        rethrow;
      }
    }
  });
}