uploadToDiawi method

Future<String?> uploadToDiawi(
  1. String filePath
)

Main upload method that handles both APK and IPA files

Implementation

Future<String?> uploadToDiawi(String filePath) async {
  try {
    // Validate file exists
    final file = File(filePath);
    if (!file.existsSync()) {
      print('❌ File not found: $filePath');
      return null;
    }

    // Detect file type
    final fileExtension = path.extension(filePath).toLowerCase();
    if (fileExtension != '.apk' && fileExtension != '.ipa') {
      print(
          '❌ Unsupported file type. Only .apk and .ipa files are supported.');
      return null;
    }

    print(
        'πŸ“€ Uploading ${fileExtension.substring(1).toUpperCase()} to Diawi...');

    // Step 1: Upload file and get job token
    final jobToken = await _uploadFile(file);
    if (jobToken == null) {
      print('❌ Failed to upload file to Diawi');
      return null;
    }

    print('βœ… File uploaded successfully. Job token: $jobToken');
    print('⏳ Processing upload... This may take a few minutes.');

    // Step 2: Poll for status
    final downloadLink = await _pollForStatus(jobToken);
    if (downloadLink != null) {
      print('βœ… Upload completed successfully!');
      FlutterReleaseXIndividualUploadService.updateUrlLinkState(downloadLink);
      return downloadLink;
    } else {
      print('❌ Failed to get download link from Diawi');
      return null;
    }
  } catch (e) {
    print('❌ Error uploading to Diawi: $e');
    return null;
  }
}