uploadFile method

Future<FileUploadResponse> uploadFile(
  1. String filePath, {
  2. String fieldName = 'file',
  3. Map<String, dynamic>? metadata,
  4. void onProgress(
    1. double progress
    )?,
})

Upload a file

Implementation

Future<FileUploadResponse> uploadFile(
  String filePath, {
  String fieldName = 'file',
  Map<String, dynamic>? metadata,
  void Function(double progress)? onProgress,
}) async {
  final response = await _apiClient.uploadFile<Map<String, dynamic>>(
    '/files/upload',
    filePath,
    fieldName: fieldName,
    additionalData: metadata,
    onProgress: (sent, total) {
      if (onProgress != null && total > 0) {
        onProgress(sent / total);
      }
    },
  );

  return FileUploadResponse.fromJson(response);
}