Skip to content

Commit 6d0bdcb

Browse files
fixes and implemented legacy statistics data page
1 parent 5e5c57d commit 6d0bdcb

30 files changed

Lines changed: 2924 additions & 1102 deletions

File tree

school_data_hub_flutter/lib/common/data/file_upload_service.dart

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,57 @@ class ClientFileUpload {
1515
static final _instance = ClientFileUpload.__internal();
1616
factory ClientFileUpload() => _instance;
1717

18-
// TODO: consider exceptions here
1918
static Future<({String? path, bool success})> uploadFile(
20-
File file, ServerStorageFolder folder) async {
19+
File file,
20+
ServerStorageFolder folder,
21+
) async {
2122
final documentId = const Uuid().v4();
2223
final path = p.join(folder.name, '$documentId${p.extension(file.path)}');
23-
final uploadDescription =
24-
await _client.files.getUploadDescription(StorageId.private.name, path);
25-
if (uploadDescription != null) {
26-
// Create an uploader
27-
final uploader = FileUploader(uploadDescription);
28-
29-
// Upload the file
30-
final fileStream = file.openRead();
31-
32-
final fileLength = await file.length();
33-
_notificationService.apiRunning(true);
34-
await uploader.upload(fileStream, fileLength);
35-
_notificationService.apiRunning(false);
36-
37-
// Verify the upload
38-
try {
39-
final success =
40-
await _client.files.verifyUpload(StorageId.private.name, path);
41-
return (path: path, success: success);
42-
} catch (e) {
43-
_log.severe('Upload failed for $path: $e');
44-
_notificationService.showSnackBar(
45-
NotificationType.error, 'Upload failed for $path: $e');
46-
return (path: null, success: false);
24+
try {
25+
final uploadDescription = await _client.files.getUploadDescription(
26+
StorageId.private.name,
27+
path,
28+
);
29+
_log.info('Upload description received for $path');
30+
_log.fine('Upload description: $uploadDescription');
31+
32+
if (uploadDescription != null) {
33+
// Create an uploader
34+
final uploader = FileUploader(uploadDescription);
35+
36+
// Upload the file
37+
final fileStream = file.openRead();
38+
39+
final fileLength = await file.length();
40+
_notificationService.apiRunning(true);
41+
await uploader.upload(fileStream, fileLength);
42+
_notificationService.apiRunning(false);
43+
44+
// Verify the upload
45+
try {
46+
final success = await _client.files.verifyUpload(
47+
StorageId.private.name,
48+
path,
49+
);
50+
return (path: path, success: success);
51+
} catch (e) {
52+
_log.severe('Upload failed for $path: $e');
53+
_notificationService.showSnackBar(
54+
NotificationType.error,
55+
'Upload failed for $path: $e',
56+
);
57+
return (path: null, success: false);
58+
}
4759
}
60+
} catch (e) {
61+
_log.severe('Failed to get upload description for $path: $e');
62+
_notificationService.showSnackBar(
63+
NotificationType.error,
64+
'Failed to get upload description for $path: $e',
65+
);
66+
return (path: null, success: false);
4867
}
68+
4969
_log.severe('Upload description is null for $path');
5070
return (path: null, success: false);
5171
}

0 commit comments

Comments
 (0)