uploadMultipleFiles method

Future<List<String>> uploadMultipleFiles({
  1. required String url,
  2. required List<String> filePaths,
  3. String fileKey = 'files',
  4. Map<String, dynamic>? formData,
  5. Map<String, dynamic>? headers,
  6. bool useWithoutToken = false,
  7. CancelToken? cancelToken,
  8. void onSendProgress(
    1. int,
    2. int
    )?,
})

Implementation

Future<List<String>> uploadMultipleFiles({
  required String url,
  required List<String> filePaths,
  String fileKey = 'files',
  Map<String, dynamic>? formData,
  Map<String, dynamic>? headers,
  bool useWithoutToken = false,
  CancelToken? cancelToken,
  void Function(int, int)? onSendProgress,
}) async {
  try {
    final formDataMap = FormData.fromMap({
      ...?formData,
      fileKey: filePaths.map((path) => MultipartFile.fromFileSync(path)).toList(),
    });

    final response = await _dio.post(
      url,
      data: formDataMap,
      options: Options(
        headers: headers,
        extra: {'useWithoutToken': useWithoutToken},
      ),
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
    );

    return List<String>.from(response.data['paths'] ?? response.data['urls']);
  } on DioException catch (e) {
    throw _handleDioError(e);
  }
}