Task file attachments

This commit is contained in:
Marc Rejohn Castillano 2026-03-01 22:11:21 +08:00
parent 3950f3ee94
commit b9722106ff
2 changed files with 1009 additions and 294 deletions

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'dart:convert';
@ -741,6 +742,64 @@ class TasksController {
}
}
Future<void> uploadTaskAttachment({
required String taskId,
required String fileName,
required Uint8List bytes,
}) async {
final path = '$taskId/$fileName';
try {
debugPrint('uploadTaskAttachment uploading to path: $path');
final dynamic res;
if (kIsWeb) {
// on web, upload binary data
res = await _client.storage
.from('task_attachments')
.uploadBinary(path, bytes);
} else {
// write bytes to a simple temp file (no nested folders)
final tmpDir = Directory.systemTemp;
final localFile = File(
'${tmpDir.path}/${DateTime.now().millisecondsSinceEpoch}_$fileName',
);
try {
await localFile.create();
await localFile.writeAsBytes(bytes);
} catch (e) {
debugPrint('uploadTaskAttachment failed writing temp file: $e');
rethrow;
}
res = await _client.storage
.from('task_attachments')
.upload(path, localFile);
try {
await localFile.delete();
} catch (_) {}
}
debugPrint(
'uploadTaskAttachment response type=${res.runtimeType} value=$res',
);
// Check for errors
if (res is String) {
// treat as success
} else if (res is Map && res['error'] != null) {
debugPrint('uploadTaskAttachment upload error: ${res['error']}');
throw Exception('Upload error: ${res['error']}');
} else if (res != null && res.error != null) {
debugPrint('uploadTaskAttachment upload error: ${res.error}');
throw Exception('Upload error: ${res.error}');
}
} catch (e) {
debugPrint('uploadTaskAttachment failed: $e');
rethrow;
}
}
Future<void> _notifyCreated({
required String taskId,
required String? actorId,

File diff suppressed because it is too large Load Diff