uploadSingleFile static method

Future<void> uploadSingleFile(
  1. File file
)

Example 1: Upload a single file using the uploadFile method

Implementation

static Future<void> uploadSingleFile(File file) async {
  final environment = createEnvironment();
  final endpoint = GtdEndpoint(env: environment, path: 'upload');

  // Configure the network service
  final networkService = GtdNetworkService.shared;
  networkService.request = GTDNetworkRequest(
    type: GtdMethod.post,
    enpoint: endpoint,
    data: {
      'description': 'File uploaded from Flutter app',
      'timestamp': DateTime.now().toIso8601String(),
    },
  );

  try {
    final response = await networkService.uploadFile(
      file: file,
      fieldName: 'file',
      extraData: {
        'type': 'profile_image',
      },
      onSendProgress: (int sent, int total) {
        final progress = (sent / total * 100).toStringAsFixed(2);
        print('Upload progress: $progress%');
      },
    );

    print('Upload successful: ${response.statusCode}');
    print('Response data: ${response.data}');
  } on DioException catch (e) {
    print('Upload failed: ${e.message}');
  }
}