uploadFile method

Future<Response> uploadFile(
  1. String path, {
  2. required File file,
  3. String fileKey = "file",
  4. Map<String, dynamic>? data,
  5. ProgressCallback? onProgress,
})

===================================================== 🔥 SINGLE FILE UPLOAD (Image / PDF / DOC)

Implementation

Future<Response> uploadFile(
    String path, {
      required File file,
      String fileKey = "file",
      Map<String, dynamic>? data,
      ProgressCallback? onProgress,
    }) async {
  final fileName = file.path.split('/').last;

  FormData formData = FormData.fromMap({
    if (data != null) ...data,

    fileKey: await MultipartFile.fromFile(
      file.path,
      filename: fileName,
    ),
  });

  return await _dio.post(
    path,
    data: formData,
    onSendProgress: onProgress,
    options: Options(
      contentType: "multipart/form-data",
    ),
  );
}