renameItem method

Future<void> renameItem(
  1. String oldPath,
  2. String newPath
)

Implementation

Future<void> renameItem(String oldPath, String newPath) async {
  try {
    final sourceUrl = Uri.parse('$baseUrl$oldPath');
    final destinationUrl = Uri.parse('$baseUrl$newPath');

    final response = http.Request('MOVE', sourceUrl)
      ..headers.addAll(_getHeaders())
      ..headers['Destination'] = destinationUrl.toString();

    final streamedResponse = await response.send();
    final statusCode = streamedResponse.statusCode;

    if (statusCode == 201 || statusCode == 204) {
      // Item renamed successfully
    } else {
      await streamedResponse.stream.bytesToString(); // Consume response
      throw Exception('Failed to rename item: $statusCode');
    }
  } catch (e) {
    rethrow;
  }
}