uploadFile method

Future<File> uploadFile({
  1. String? filePath,
  2. Uint8List? bytes,
  3. String uploadUrl = "/upload-file",
  4. String? filename,
})

Uploads a single file.

On web, provide bytes and filename. On native, you can provide either a filePath or bytes (with optional filename).

Implementation

Future<File> uploadFile({
  String? filePath,
  Uint8List? bytes,
  String uploadUrl = "/upload-file",
  String? filename,
}) async {
  try {
    final formData = await _buildSingleFileFormData(
      filePath: filePath,
      bytes: bytes,
      filename: filename,
    );
    final response = await dio.post(uploadUrl, data: formData);
    return response.body<File>();
  } catch (e) {
    rethrow;
  }
}