uploadFile method

Future<bool> uploadFile({
  1. required File file,
  2. String? title,
  3. String? comment,
})

Upload a file to Slack using the new three-step process This replaces the deprecated files.upload method

Implementation

Future<bool> uploadFile({
  required File file,
  String? title,
  String? comment,
}) async {
  try {
    _debugLog('Starting file upload: ${file.path}');

    // Step 1: Get upload URL and file ID from Slack
    final uploadInfo = await _getUploadUrl(file);
    if (uploadInfo == null) {
      print('❌ Failed to get upload URL from Slack');
      return false;
    }

    _debugLog('✅ Got upload URL and file ID');

    // Step 2: Upload file to the provided URL
    final uploadSuccess = await _uploadToUrl(file, uploadInfo);
    if (!uploadSuccess) {
      print('❌ Failed to upload file to provided URL');
      return false;
    }

    _debugLog('✅ File uploaded to URL successfully');

    // Step 3: Complete the upload and post to channel
    final success = await _completeUpload(
      fileId: uploadInfo['file_id'],
      title: title,
      comment: comment,
    );

    if (success) {
      print('✅ File uploaded to Slack successfully');
    } else {
      print('❌ Failed to complete file upload to Slack');
    }

    return success;
  } catch (e) {
    _debugLog('❌ Exception during file upload: $e');
    print('❌ Failed to upload file to Slack: $e');
    return false;
  }
}