putApk method

Future<void> putApk({
  1. required String uploadUrl,
  2. required File apkFile,
  3. required int fileSize,
  4. required String projectType,
  5. String? flavor,
})

Implementation

Future<void> putApk({
  required String uploadUrl,
  required File apkFile,
  required int fileSize,
  required String projectType,
  String? flavor,
}) async {
  try {
    final storageDio =
        Dio(); // No auth header — signed URL is self-authenticating
    await storageDio.put(
      uploadUrl,
      data: apkFile.openRead(),
      options: Options(
        headers: {
          'Content-Type': 'application/vnd.android.package-archive',
          'Content-Length': fileSize,
        },
        // Disable Dio's default content-type so our header wins
        contentType: 'application/vnd.android.package-archive',
      ),
      onSendProgress: AppLogger.ci
          ? null
          : (sent, total) {
              if (total <= 0) return;
              final pct = (sent / total * 100).round();
              stdout.write(
                '\r  [${'=' * (pct ~/ 5)}${' ' * (20 - pct ~/ 5)}] $pct%  ',
              );
            },
    );
    if (!AppLogger.ci) stdout.writeln('');
  } on DioException catch (e) {
    CliAnalytics.ins.logUploadFailed(
      errorCode: 'storage_failed',
      projectType: projectType,
      flavor: flavor,
    );
    AppLogger.error('Upload to Firebase Storage failed: ${e.message}');
    exit(ExitCodes.storageFailed);
  }
}