startUpload method

  1. @override
Future<String> startUpload({
  1. required String filePath,
  2. required String uploadUrl,
  3. Map<String, String>? headers,
  4. Map<String, String>? fields,
})
override

Starts a file upload operation in the background.

filePath The local path of the file to upload. uploadUrl The URL where the file should be uploaded to. headers Optional HTTP headers to include in the upload request. fields Optional form fields to include in the multipart upload request.

Returns a task ID string that can be used to track the upload progress or cancel the operation.

Throws an Exception if the upload fails to start.

Implementation

@override
Future<String> startUpload({
  required String filePath,
  required String uploadUrl,
  Map<String, String>? headers,
  Map<String, String>? fields,
}) async {
  try {
    final taskId = await _channel.invokeMethod('startUpload', {
      'file_path': filePath,
      'upload_url': uploadUrl,
      'headers': headers,
      'fields': fields,
    });
    return taskId as String;
  } on PlatformException catch (e) {
    throw Exception("Failed to start upload: ${e.message}");
  }
}